how does this work?

Started by
18 comments, last by original vesoljc 21 years, 4 months ago
#if sizeof(int) != 4
#error You duffed this big time, mi''laddo...
#endif

Etc...

Member of the Unban Mindwipe Society (UMWS)
Advertisement
Can you use sizeof in an #if expression? And is #error portable?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
can u? (sizeof)
is it? (error)


Abnormal behavior of abnormal brain makes me normal...
Abnormal behavior of abnormal brain makes me normal...
quote:Original post by Kylotan
Can you use sizeof in an #if expression?

No.
quote:And is #error portable?

Yes.
quote:Original post by Kylotan
Can you use sizeof in an #if expression?


You can use templates to generate errors based on types or type properties and to do compile-time type manipulations in general.

see Loki, Boost...

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:Original post by Fruny
You can use templates to generate errors based on types or type properties and to do compile-time type manipulations in general.

Not in C you can''t.
quote:Original post by SabreMan
Not in C you can''t.


Nor in Fortran.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:Original post by Fruny
Nor in Fortran.

Yes, but the SDL API isn''t written in Fortran.
quote:Original post by SabreMan
Yes, but the SDL API isn''t written in Fortran.


But Fortran uses the C preprocessor. Thus you can use #if.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | Free C++ IDE. ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Boost C++ Lib ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:Original post by Fruny
But Fortran uses the C preprocessor. Thus you can use #if.

Can use #if for what? You can''t use it to assert on the size of a type, since #if is a preprocessor macro, and preprocessing occurs before tokenising, which means you don''t have the size of the variable at that time. I can''t help but wonder what point you are trying to make.

This topic is closed to new replies.

Advertisement