473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2040
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
2
by: Subodh | last post by:
Hi, Currently we get data from more then 200 different sources and all of our vendors provide data in different file formats. The problem is we have more then 100 DTS packages now and the...
2
by: REH | last post by:
If the is_modulo field of the numeric_limits class is true for signed integer types, can I assume that overflow for such types is defined behavior? If so, is the behavior the same regardless of...
19
by: shanx__=|;- | last post by:
hi i need some help regarding use of very very long integer datatype in 'c'.. i need it to store result of large number's factorial.. if someone can healp it would be a delight..
2
by: Mark Jerde | last post by:
(If these are the wrong groups please suggest the right one(s). Thanks.) I need to come up with a way to test potentially thousands of data (files / records / streams) to determine if they match...
43
by: Steven T. Hatton | last post by:
http://public.research.att.com/~bs/bs_faq2.html#int-to-string Is there no C library function that will take an int and convert it to its ascii representation? The example Bjarne shows in his faq...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
8
by: john.goodleaf | last post by:
I'm poking at writing data out to a SAS XPORT file (transport file). Each record must be 80 bytes long, ASCII. Integers should be "IBM- style integers" and floats should be "IBM-style doubles." Now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.