This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Distinguishing between long and long long on an LP64 machine?


Suppose that I have a signed integer type coming from a header
file, and that I already know that this integer type is a 64-bit
type. (Think off_t, for example.) If I'm using gcc on a machine
where both long and long long also have 64 bits, is there any
simple C99 (+ gcc extension) code that will allow me to figure
out whether this type is ultimately defined as long or long long?

The original motivation was to avoid gcc -Wall warnings when
doing:

off_t my_offset;
...
printf("%lld", my_offset);

If off_t is defined as long rather than long long then this will
give a warning, even though the sizes match.  (So of course,
this actually gives a programmatic way to distinguish: have
a configure script do a test compilation with -Wall -Werror.
But I'm looking for a simple C expression or function that
could detect the difference.)

It seems that some LP64 platforms (e.g., OS X 10.6) define
off_t to be long long, while others (e.g., Linux/x86_64, or at least
the three different flavours of Linux that I tested) define off_t
to be long.

Of course, the solution to avoiding printf warnings is as easy
as adding a cast:

printf("%lld", (long long)my_offset);

so in this particular motivating case there isn't really
any problem.  But I'm still curious to know
whether there's a simple way for a gcc *user* to distinguish
between long and long long when both are 64 bits.  typeof
doesn't seem to help here.  I guess I'm really after some
imaginary extension 'rank_of' that lets me do

if (rank_of(off_t) == rank_of(long long))
< code using %lld >
else
< code using %ld >
...

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]