Re: C89 "bug"

Liste des GroupesRevenir à cl c  
Sujet : Re: C89 "bug"
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 14. Dec 2024, 07:02:22
Autres entêtes
Organisation : None to speak of
Message-ID : <87bjxevm35.fsf@nosuchdomain.example.com>
References : 1 2
User-Agent : Gnus/5.13 (Gnus v5.13)
antispam@fricas.org (Waldek Hebisch) writes:
Thiago Adams <thiago.adams@gmail.com> wrote:
Does anyone knows how can I convert this code (external declaration) to C89?
 
union U {
    int i;
    double d;
};
 
union U  u = {.d=1.2};
 
The problem is that in C89 only the first member of the union is
initialized.
>
The following:
>
union U {
    int i;
    double d;
};
>
union U u = (union U)(1.2);
>
is accepted by 'gcc -S -std=c90'.  I leave to others to check
if this is valid C89.

It's not.  With "-std=c90 -pedantic", gcc (correctly) warns:

    ISO C forbids casts to union type [-Wpedantic]

The specific constraint in the C90 standard is:

    Unless the type name specifies void type, the type name shall
    specify qualified or unqualified scalar type and the operand
    shall have scalar type.

(Later editions have similar wording.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
13 Dec 24 * C89 "bug"17Thiago Adams
13 Dec 24 +* Re: C89 "bug"6Michael S
13 Dec 24 i`* Re: C89 "bug"5Thiago Adams
13 Dec 24 i `* Re: C89 "bug"4Kaz Kylheku
13 Dec 24 i  `* Re: C89 "bug"3Thiago Adams
13 Dec 24 i   `* Re: C89 "bug"2bart
13 Dec 24 i    `- Re: C89 "bug"1Thiago Adams
13 Dec 24 +* Re: C89 "bug"8Keith Thompson
13 Dec 24 i`* Re: C89 "bug"7Thiago Adams
13 Dec 24 i +* Re: C89 "bug"5David Brown
13 Dec 24 i i+* Re: C89 "bug"2Thiago Adams
13 Dec 24 i ii`- Re: C89 "bug"1Thiago Adams
14 Dec 24 i i`* Re: C89 "bug"2bart
15 Dec 24 i i `- Re: C89 "bug"1David Brown
13 Dec 24 i `- Re: C89 "bug"1Keith Thompson
14 Dec 24 `* Re: C89 "bug"2Waldek Hebisch
14 Dec 24  `- Re: C89 "bug"1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal