This is the mail archive of the 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]

Re: Distinguishing between long and long long on an LP64 machine?

Hi Mark,

> 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?

If you are using C++, yes.  If you are using C... I don't think so.

For your example, this is how I do it:

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

Why?  Because there is no printf format specifier for off_t:

printf("%{off_t}d", my_offset);

And *that* is really the problem you are running into.  (If I recall
correctly, C/C++ Users Journal had published an article on extensible printf
called eprintf, and there you could register off_t handling.)

If you are using C99, then you could do it this way:

#include <inttypes.h>
off_t my_offset;
printf("%"PRId64, (int64_t)my_offset);

That's even more port-robust.  For the ultimate in future-protection
paranoia, you could add a static check to ensure that sizeof(off_t) ==
sizeof(int64_t).  I think that's about as close as you can get, and it
doesn't distinguish between long int and long long if both are 64-bit.

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

C?  I don't think so.

C++?  Yes, standard C++.  (You can use C++ as a "better C".  But these days,
that will probably get you scowls from C folks who eschew C++.)


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