469,275 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

integer formats

hi all,

in http://www.c-faq.com/cpp/ifendian.html

it is said that integer formats used in pre processor #if expressions
are
not the same as those will be used at run time.

can any one explain about this difference in formats???

Apr 26 '06 #1
8 1801
aa*****@gmail.com said:
hi all,

in http://www.c-faq.com/cpp/ifendian.html

it is said that integer formats used in pre processor #if expressions
are
not the same as those will be used at run time.
What it actually says is: "At any rate, the integer formats used in
preprocessor #if expressions are not necessarily the same as those that
will be used at run time."

Note the phrase 'not necessarily'.
can any one explain about this difference in formats???


Consider, for example, the case of a cross-compiler, which runs on a
big-endian machine but which compiles code for use on a little-endian
machine. The preprocessor will of course run on the big-endian box (in this
example), so it will use big-endian integers - but the object code will be
executed on the little-endian machine (in this example), so it will use
little-endian integers.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 26 '06 #2
Richard Heathfield wrote:
aa*****@gmail.com said:
hi all,

in http://www.c-faq.com/cpp/ifendian.html

it is said that integer formats used in pre processor #if expressions
are not the same as those will be used at run time.


What it actually says is: "At any rate, the integer formats used in
preprocessor #if expressions are not necessarily the same as those that
will be used at run time."

Note the phrase 'not necessarily'.
can any one explain about this difference in formats???


Consider, for example, the case of a cross-compiler, which runs on a
big-endian machine but which compiles code for use on a little-endian
machine. The preprocessor will of course run on the big-endian box (in this
example), so it will use big-endian integers - but the object code will be
executed on the little-endian machine (in this example), so it will use
little-endian integers.


Endianness and host v target issues are all but irrelevant to the
preprocessor
since it deals with values, not objects!

The FAQ's use of the word 'Format' is perhaps misleading. The real
issue
is that the preprocessor performs calculations using only the largest
integer
type(s). Thus, the preprocessor doesn't always evaluate expressions in
the
same way that the same expression would be evaluated in later
translation
phases...

% type ppm1.c
#include <stdio.h>

int main(void)
{
if (-1 == 4294967295)
{
puts("test 1");
}

#if (-1 == 4294967295)
puts("test 2");
#endif

return 0;
}

% acc ppm1.c -o ppm1.exe
ppm1.c: In function `main':
ppm1.c:5: warning: this decimal constant is unsigned only in ISO C90
ppm1.c:5: warning: comparison between signed and unsigned

% ppm1.exe
test 1

%

By rights, this program should either produce both "test 1" and "test
2", or
neither. However, because the preprocessor uses different 'arithmetic'
to
evaluate expressions, my implementation produced only one output line,
even though the two tests were identical.

--
Peter

Apr 26 '06 #3
Peter Nilsson said:
Endianness and host v target issues are all but irrelevant to the
preprocessor
since it deals with values, not objects!


Um, quite so - but if it /did/ deal with objects, my answer would have
looked pretty good. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 26 '06 #4
does this mean that pre processor uses only signed long data type
only????

Apr 26 '06 #5
aa*****@gmail.com wrote:
does this mean that pre processor uses only signed long data type
only????


Click on 'More Options' and 'Add Reply' to quote context. No one knows
what you're saying. The last message in this thread was Richard
Heathfield talking about one of his previous posts.
Apr 26 '06 #6
Richard Heathfield <in*****@invalid.invalid> writes:
aa*****@gmail.com said:
hi all,

in http://www.c-faq.com/cpp/ifendian.html

it is said that integer formats used in pre processor #if expressions
are
not the same as those will be used at run time.


What it actually says is: "At any rate, the integer formats used in
preprocessor #if expressions are not necessarily the same as those that
will be used at run time."

Note the phrase 'not necessarily'.
can any one explain about this difference in formats???


Consider, for example, the case of a cross-compiler, which runs on a
big-endian machine but which compiles code for use on a little-endian
machine. The preprocessor will of course run on the big-endian box (in this
example), so it will use big-endian integers - but the object code will be
executed on the little-endian machine (in this example), so it will use
little-endian integers.


I fail to see how endian issues are a concern of a preprocessor.
Apr 27 '06 #7
Richard G. Riley said:
Richard Heathfield <in*****@invalid.invalid> writes:
Consider, for example, the case of a cross-compiler, which runs on a
big-endian machine but which compiles code for use on a little-endian
machine. The preprocessor will of course run on the big-endian box (in
this example), so it will use big-endian integers - but the object code
will be executed on the little-endian machine (in this example), so it
will use little-endian integers.


I fail to see how endian issues are a concern of a preprocessor.


Well, if they *were*, then my answer would make sense.

Likewise, if red were a giraffe, roses would have better camouflage.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 30 '06 #8
Richard Heathfield <in*****@invalid.invalid> writes:
Richard G. Riley said:
Richard Heathfield <in*****@invalid.invalid> writes:
Consider, for example, the case of a cross-compiler, which runs on a
big-endian machine but which compiles code for use on a little-endian
machine. The preprocessor will of course run on the big-endian box (in
this example), so it will use big-endian integers - but the object code
will be executed on the little-endian machine (in this example), so it
will use little-endian integers.


I fail to see how endian issues are a concern of a preprocessor.


Well, if they *were*, then my answer would make sense.

Likewise, if red were a giraffe, roses would have better camouflage.


Why would Roses want to have better camouflage? And I know a giraffe
called Red (well, "big red" to be precise). So from this I deduce that
Roses have better camouflage : but better than what I'm not sure.
May 2 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Richard Hollenbeck | last post: by
2 posts views Thread by REH | last post: by
19 posts views Thread by shanx__=|;- | last post: by
2 posts views Thread by Mark Jerde | last post: by
43 posts views Thread by Steven T. Hatton | last post: by
39 posts views Thread by rembremading | last post: by
8 posts views Thread by john.goodleaf | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.