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.)
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?
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (0 / 16) |
Uptime: | 162:55:05 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,508 |