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 : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 18. Jul 2024, 05:44:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <868qxz5ppx.fsf@linuxsc.com>
References : 1
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

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.

Or it might be that the compiler was a pre-ANSI-standard compiler,
where a "non-conforming" label has no meaning.

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?

Even if there were a C compiler where 0 has a type other than
int, it seems unlikely that the cast would be necessary.  I
haven't bothered to check, but my recollection is that even
K&R C allowed assignment between different numerical types.
And surely every numerical type includes a representation
for the abstract value 0.

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