- Chameleon - wrote:
How can I write this correctly?
#if sizeof(int) < sizeof(my_int)
.............
#endif
You can't. the value of sizeof() is not evaluated by the preprocessor.
Therefore, you can't use it in preprocessor conditionals. You could do:
#include <climits>
#define MY_INT_MAX some_value
#if INT_MAX < MY_INT_MAX
//something
#else
//something else
#endif
or you use templates: (untested)
template <bool b>
void my_function_internal()
{
//something
}
template <>
void my_function_internal<false>()
{
//something else
}
void my_function()
{
my_function_internal<(sizeof(int) < sizeof(my_int))>();
}