Deutsch   English   Français   Italiano  
<87jzc3v48r.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: C89 "bug"
Date: Fri, 13 Dec 2024 10:15:32 -0800
Organization: None to speak of
Lines: 27
Message-ID: <87jzc3v48r.fsf@nosuchdomain.example.com>
References: <vjh8hu$3den0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Fri, 13 Dec 2024 19:15:33 +0100 (CET)
Injection-Info: dont-email.me; posting-host="66c77e050ec176338b057ef443530fd1";
	logging-data="3732068"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18aC1RAtSZal8W/ZhL6bo5T"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:DTxqRqgpHb/HmZkjAi259RP4O7A=
	sha1:q7FzDLsR2rbTSmaUh5BjQNcdSnI=
Bytes: 1607

Thiago Adams <thiago.adams@gmail.com> writes:
> 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 obvious solution is:
    union U u;
    u.d = 1.2;
But that works only if u has automatic storage duration.

You could also define a function that takes a double argument and
returns a union U result.

Of course the best solution is to use C99 or later, unless there's
some reason you can't.

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