Code Comments
Programming Forum and web based access to our favorite programming groups.How can I write this correctly? #if sizeof(int) < sizeof(my_int) ............. #endif I want compile different pieces of code for different platforms
Post Follow-up to this message"<- Chameleon ->" <cham_gss@hotmail.NOSPAM.com> wrote in message news:c4lv0p$bbl$1@nic.grnet.gr... > How can I write this correctly? > > #if sizeof(int) < sizeof(my_int) > ............. > #endif > > I want compile different pieces of code for different platforms > > You can't in the preprocessor but you could use specialization of templates based on sizeof
Post Follow-up to this message- 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))>();
}
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.