64 bit architectures and C/C++
Clive Feather
clive at x.co.uk
Thu May 9 16:28:20 AEST 1991
In article <1991May6.232116.11401 at sq.sq.com> msb at sq.sq.com (Mark Brader) writes:
> I disagree. I think "long long" is a preferable approach.
[...]
> A programmer wishing
> to do arithmetic on integer values exceeding what can be stored in
> 32 bits has three options:
[...]
> (c) use an integral type known to provide the required number of bits,
> and never port the program to machines where no such type exists.
[...]
> Now, what would we like to happen if a program that assumed 64-bit
> integers existed was ported to a machine where they didn't? We would
> like the compilation to fail, that's what! Suppose that the implementation
> defines long to be 64 bits; then, to force such a failure, the programmer
> would have to take some explicit action, like
>
> assert (LONG_MAX >= 0777777777777777777777);
>
> On the other hand, suppose that the implementation defines a separate
> "long long" type for 64-bit integers. Then when the user compiles the
> program on the 64-bit machine, they get:
>
> cc: warning: "long long" is an extension and not portable
>
> and, assuming a reasonable quality of implementation, they can eliminate
> this message with a cc option if desired. And if they do try to port,
> they get a fatal error in compilation.
>
> This behavior seems exactly right to me.
If you want the compilation to fail, then what's wrong with the
following ?
#if LONG_MAX < 0xFFFFffffFFFFffff
??=error Long type not big enough for use.
#endif
This causes the compilation to fail only when long is not big enough,
does not require any new types in the implementation, and generates *no*
messages on an 64-bit-long system.
Notes: the use of a hex, rather than octal, constant awith mixed case
makes it easier to count the number of digits, and the explicit trigraph
is used to choke (non-ANSI) implementations which don't have #error, and
which might object to it even when the condition of the #if is false.
--
Clive D.W. Feather | IXI Limited | If you lie to the compiler,
clive at x.co.uk | 62-74 Burleigh St. | it will get its revenge.
Phone: +44 223 462 131 | Cambridge CB1 1OJ | - Henry Spencer
(USA: 1 800 XDESK 57) | United Kingdom |
More information about the Comp.lang.c
mailing list