#if sizeof(int) != 4
#error You duffed this big time, mi''laddo...
#endif
Etc...
how does this work?
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 ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
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 ]
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 ]
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 ]
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
Popular Topics
Advertisement