Re: "C" compiler where 0 is not of type int?

Liste des GroupesRevenir à l c 
Sujet : Re: "C" compiler where 0 is not of type int?
De : richard (at) *nospam* damon-family.org (Richard Damon)
Groupes : comp.lang.c
Date : 18. Jul 2024, 05: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.

Date Sujet#  Auteur
18 Jul 24 * "C" compiler where 0 is not of type int?4Keith Thompson
18 Jul 24 +* Re: "C" compiler where 0 is not of type int?2Richard Damon
18 Jul 24 i`- Re: "C" compiler where 0 is not of type int?1David Brown
18 Jul 24 `- Re: "C" compiler where 0 is not of type int?1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal