J
John Smith
Hi
I'm porting some C++ code to new platforms and have some 1-byte aligned
structures which need a specific size. Since datatypes can vary on different
platforms (which I found out the hard way since longs are not the same size
on win64 and linux x64) I would like to do a check at compile time to make
sure things are correct. This will ease future work.
Is it possible to do something like the following at preprocessing stage:
typedef struct _aaa
{
UINT32 a;
UINT16 b;
}aaa;
#if sizeof(aaa) != (4 + 2)
#error "Wrong settings for this platform"
#endif
The compiler seems to fail no matter which platform I use. I know I can do
this at runtime but it's not useful code so I rather not have it done at
runtime. The only alternative is to enable it as a runtime check when
compiling in debug mode.
Thanks in advance.
-- John
I'm porting some C++ code to new platforms and have some 1-byte aligned
structures which need a specific size. Since datatypes can vary on different
platforms (which I found out the hard way since longs are not the same size
on win64 and linux x64) I would like to do a check at compile time to make
sure things are correct. This will ease future work.
Is it possible to do something like the following at preprocessing stage:
typedef struct _aaa
{
UINT32 a;
UINT16 b;
}aaa;
#if sizeof(aaa) != (4 + 2)
#error "Wrong settings for this platform"
#endif
The compiler seems to fail no matter which platform I use. I know I can do
this at runtime but it's not useful code so I rather not have it done at
runtime. The only alternative is to enable it as a runtime check when
compiling in debug mode.
Thanks in advance.
-- John