Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

sizeof in preprocessor
How can I write this correctly?

#if sizeof(int) < sizeof(my_int)
.............
#endif

I want compile different pieces of code for different platforms



Report this thread to moderator Post Follow-up to this message
Old Post

04-03-04 12:32 PM


Re: sizeof in preprocessor
"<- 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




Report this thread to moderator Post Follow-up to this message
Old Post
Nick Hounsome
04-03-04 05:31 PM


Re: sizeof in preprocessor
- 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))>();
}


Report this thread to moderator Post Follow-up to this message
Old Post
Rolf Magnus
04-03-04 05:32 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C++ archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:18 AM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.