K
Kenneth Brody
Is sizeof() legal within a #if preprocessor line?
Specifically, I would like to use the following "sanity check" at compile
time, but I'm getting an error on the compile about the #if line.
struct foo {
int a;
int b;
};
#if sizeof(struct foo) != 8
#pragma error "sizeof foo is not 8!"
#endif
(Assuming the "#pragma error" generates a compile-time error.)
Yes, I know all about the dangers and non-portability of things like this,
but it's in a low-level TCP/IP communications module, and I'd just like to
add a sanity check at compile time that I'm not on a platform where the
structs don't match the communications protocol.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
Specifically, I would like to use the following "sanity check" at compile
time, but I'm getting an error on the compile about the #if line.
struct foo {
int a;
int b;
};
#if sizeof(struct foo) != 8
#pragma error "sizeof foo is not 8!"
#endif
(Assuming the "#pragma error" generates a compile-time error.)
Yes, I know all about the dangers and non-portability of things like this,
but it's in a low-level TCP/IP communications module, and I'd just like to
add a sanity check at compile time that I'm not on a platform where the
structs don't match the communications protocol.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>