integer formats

R

Richard Heathfield

(e-mail address removed) 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.
 
P

Peter Nilsson

Richard said:
(e-mail address removed) said:

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'.


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.
 
R

Richard Heathfield

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. :)
 
A

Andrew Poelstra

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.
 
R

Richard G. Riley

Richard Heathfield said:
(e-mail address removed) said:


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'.


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.
 
R

Richard Heathfield

Richard G. Riley said:
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.
 
R

Richard G. Riley

Richard Heathfield said:
Richard G. Riley said:


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,514
Latest member
AdeleGelle

Latest Threads

Top