Sujet : Re: "C" compiler where 0 is not of type int?
De : richard (at) *nospam* damon-family.org (Richard Damon)
Groupes : comp.lang.cDate : 18. Jul 2024, 04:35:00
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <bc98559c10d4a52c653a6fb04e23035309b9720b@i2pn2.org>
References : 1
User-Agent : Mozilla Thunderbird
On 7/17/24 11:03 PM, Keith Thompson wrote:
This is going to sound like an odd question, because it is.
I saw this code fragment in an answer posted on Quora:
// In case literal 0 isn't an int on this platform.
int z = (int) 0;
The writer encountered this in an old C project, and suggested that the
author of the code might have had a legitimate concern. (He ended up
removing the cast.)
Obviously 0 is of type int in every C standard. If the cast were
necessary, it would be because of a non-conforming compiler.
I've heard of non-conforming C compilers that make int 8 bits, or that
don't have long double, or that have a long double type that doesn't
meet the standard's range and/or precision requirements.
My question is this: Has there ever been a (non-conforming) C compiler
that gave a constant 0 a type other than int?
(I'm ignoring the use of a "//" comment; the writer may not have copied
the code verbatim.)
I thought I remembered a compiler for a small processor that didn't promote smaller than ints to int to do the arithmatic because full int arithmetic was expensive, even for just 16 bits, as the processor only worked 8 bits at a time.
Small literal values might have been considered of type char, but even on that system, the assignement would have promoted the small value so the cast wouldn't have been needed.