gcc, width of long int on different architectures
18,544
Don't do this - use standard types such as int32_t
, uint32_t
, int64_t
, uint64_t
, etc from <stdint.h>
rather than trying to make assumptions about naked types such as long int
or trying to bend the compiler to your will.
Note: The 64-bit model for any given platform (e.g. LP64 for most *nix platforms, Mac OS X, etc) is a given, so even if you could convince the compiler to use a different 64-bit model you would probably break any calls to system code, libraries, etc.
Comments
-
please delete me over 1 year
On 64-bit architectures,
long int
, according to gcc is at least anint64_t
. On 32-bit,long int
is at leastint32_t
. With Microsoft compilers,long
is always anint32_t
, regardless of 32/64-bit. Is there any way to:- Force gcc to treat long as a int64_t, on 32bit? (for ease of testing)
- Force gcc to treat long as a int32_t on 64bit? (for compliance with MS's compiler).
-
please delete me almost 13 yearsI use boost's cstdint in all my projects. I can't force other members of my team, or library authors to do the same. Forcing it at the compiler level (if at all possible) seems safer.
-
please delete me almost 13 yearsSee my comment to Goz's answer.
-
Paul R almost 13 years@John: if your team members are writing fragile/unsafe/non-portable code then you need to fix them and/or their code.