Hello all,
I am trying to find a way to set up structure packing using #define macros while also being compiler-independant. Ideally, something like this would be great:
MYSTRUCTPACK(1) struct
{
char foo;
int bar;
} hoge;
However, MSVC (and other compilers) use a #pragma with a push and pop syntax, rather than a _declspec like they use for alignment, so I've resigned myself that this is probably the best I'd ever be able to do:
MYSTRUCTPACK_BEGIN(1)
struct
{
char foo;
int bar;
} hoge;
MYSTRUCTPACK_END()
Unfortunately, MSVC doesn't like me using a #define to declare #pragma pack:
#define MYSTRUCTPACK_BEGIN(x) #pragma pack(push, x) // error C2162: expected macro formal parameter
After much fruitless searching on Google, I did manage to find
one thread here on gamedev where Null and Void pointed out how CPT handles this issue. The only problem with using a #include to wrap a structure is that I wouldn't be able to specify the desired packing (1, 2, 4, 8, 16, etc) unless I created multiple include files each with a different values.
That post was made back in 2002. Is there any better way to do this 4 years later that I'm just not aware of?