| Deutsch English Français Italiano |
|
<vjhkig$3g4cu$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: C89 "bug"
Date: Fri, 13 Dec 2024 12:41:04 -0300
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vjhkig$3g4cu$1@dont-email.me>
References: <vjh8hu$3den0$1@dont-email.me> <20241213145639.00003d71@yahoo.com>
<vjhcle$3den0$2@dont-email.me> <20241213065614.739@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 13 Dec 2024 16:41:05 +0100 (CET)
Injection-Info: dont-email.me; posting-host="8b9a0b17735b443b8fd85bb0477dd1c9";
logging-data="3674526"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mLpEmSFnLHlanVqUg4wdYzQnG6J+cxNg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:g81N30MRbC+ae63/LuDOQQFo2LI=
Content-Language: en-GB
In-Reply-To: <20241213065614.739@kylheku.com>
Bytes: 1901
Em 12/13/2024 12:01 PM, Kaz Kylheku escreveu:
> On 2024-12-13, Thiago Adams <thiago.adams@gmail.com> wrote:
>> unfortunately, this solution does not work if we have two objects.
>>
>> union U {
>> double d;
>> int i;
>> };
>>
>> union U u1 = { .d=2.2 };
>> union U u2 = { .i=1 };
>
> Idea: have several declarations of the union in different translation
> units.
>
> /* translation unit for u1 */
> union U {
> double d;
> int i;
> };
> extern union U u1 = { 2.2 };
>
> /* translation unit for u2 */
> union U {
> int i;
> double d;
> };
> extern union U u2 = { 1 };
>
another solution could be call a function that initializes before main.
extern union U u1;
void before_main()
{
u1.d = 1.2;
}