GMP and 64-bit systems

Vincent Lefevre vincent at
Sun Jun 1 21:23:42 CEST 2008

On 2008-06-01 19:30:17 +1000, Joerg Arndt wrote:
> Making long==int _and_ smaller than 64 (on a 64-bit arch) seems
> to be a concession so portability to very suboptimal code.

User code has no reason to assume that long is on 64 bits on such
architectures (BTW, if the user wants some restrictions on the type
size and/or efficiency, C99 provides types for that). IMHO the main
problem as far as the C standard is concerned is that many standard
C functions can no longer be used in some applications. A well-known
example is feesk()/ftell() whereas files larger than 4 GB are rather
common nowadays. But for some other functions, one would need the int
type to be on 64 bits too.

> Casting pointers to and from integer types is bad in the first place.
> Still, a model where long cannot hold a full address, is IMHO not sane.

There's no reason to store an address in a long (for portable code).

> With a sane model long==generic-machine-word.

There's a very clear contradiction with the above paragraph.

> > A conclusion:  any integer type intended to be 32 bits on 32-bit
> > systems and 64 bits on 64-bit systems cannot be a basic C type.  It
> > must be a typedef type, whose identity is controlled by an #ifdef in
> > some header file.
> Yes that's the price for the full adherence to the standard.

Yes, but I don't see why you would want a 32-bit type on a 32-bit
system and a 64-bit type on a 64-bit system. For something like
GMP limbs, int_fast32_t should do exactly what one wants (with
necessary #ifdef for pre-C99 implementations).

> P.S.: I was quite disappointed that the type long long was not used
> for "two machine words" but stayed at 64 bit, this also reeks like a
> concession to questionable code.

Perhaps for efficiency reasons due to old code that uses long long.
Indeed, many programmers use long long to have a type that has at
least 64 bits (if not exactly 64 bits -- which is not guaranteed),
and on a 64-bit architecture, a 64-bit type is faster than a 128-bit
type. This isn't much a problem since a 128-bit type could still be
added with a type name from <stdint.h>, and this would be cleaner,

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

More information about the gmp-discuss mailing list