Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <87bjs6hjpo.fsf@nosuchdomain.example.com>
Deutsch   English   Français   Italiano  
<87bjs6hjpo.fsf@nosuchdomain.example.com>

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

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Regarding assignment to struct
Date: Mon, 05 May 2025 13:43:31 -0700
Organization: None to speak of
Lines: 59
Message-ID: <87bjs6hjpo.fsf@nosuchdomain.example.com>
References: <vv338b$16oam$1@dont-email.me> <vv4j9p$33vhj$1@dont-email.me>
	<86plgo7ahu.fsf@linuxsc.com> <vv9hu7$3nomg$1@dont-email.me>
	<87o6w7h2wn.fsf@nosuchdomain.example.com> <868qnb5gg6.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 05 May 2025 22:43:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ce0368853eba606cbaed4ff885db219e";
	logging-data="1343581"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+UABvfFZZYFld2QiozUkoV"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:lDC10QSg/kJ9mYBhpiBJQihqxB4=
	sha1:UqXnaEWrY6jmtcGdrXBDT3vMs5o=

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Andrey Tarasevich <noone@noone.net> writes:
>> [...]
>>
>>>   #include <stdio.h>
>>>
>>>   struct S { int a[10]; };
>>>
>>>   int main()
>>>   {
>>>     struct S a, b = { 0 };
>>>     int *pa, *pb, *pc;
>>>
>>>     pa = &a.a[5];
>>>     pb = &b.a[5];
>>>     pc = &(a = b).a[5];
>>>
>>>     printf("%p %p %p\n", pa, pb, pc);
>>>   }
>>
>> [...]
>>
>> I think that code has undefined behavior.
>
> Right.  [*]
>
>> (a = b) is an rvalue that refers to an object of type struct S with
>> temporary lifetime.  pc holds the address of a subobject of that
>> temporary object.  The object reaches the end of its lifetime at the end
>> of the evaluation of the full expression.  You then print its value.
>
> Even if the printf() statement were replaced by
>
>    (void)pc;
>
> the behavior would be undefined, because the pointer held in pc
> becomes indeterminate as soon as the statement containing the
> assignment to pc completes.

Agreed.

> [*] Assuming C11 semantics.  At best inadvisable under C99
> semantics, and a constraint violation under C90 semantics.

What C90 constraint does it violate?  Both gcc and clang reject it
with "-std=c90 -pedantic-errors", with an error message "ISO C90
forbids subscripting non-lvalue array", but I don't see a relevant
constraint in the C90 standard.

I know that C11 introduced "temporary lifetime" to cover cases
like this.  In C99, the wording for the indexing operator implicitly
assumes that there's an array object; if there isn't, I'd argue the
behavior is undefined by omission.  I'm not aware of any relevant
change from C90 to C99.

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