Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.c > #396714

Re: Regarding assignment to struct

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Regarding assignment to struct
Date 2026-03-01 18:54 -0800
Organization A noiseless patient Spider
Message-ID <86ldgbeyab.fsf@linuxsc.com> (permalink)
References (6 earlier) <20250505120145.000014f8@yahoo.com> <vvame5$ppqp$1@dont-email.me> <87jz6uhkgo.fsf@nosuchdomain.example.com> <867c2u4nbd.fsf@linuxsc.com> <87r012ftl1.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> 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", (void *) pa, (void *) pb, (void *) pc);
>>>>   }
>>>>
>>>> This version has no UB.
>>>
>>> I believe it does.  [...]
>>
>> If you look again carefully, I expect you will reach a
>> different conclusion.
>
> Please explain.  Or don't.
>
> I explained, in text that you snipped, why I think it has UB.
> If there's a flaw in my reasoning, I invite you to point it out
> without being mysterious.

I wasn't thinking about your reasoning or what flaw there may have
been in it.  My intention was to suggest a course of action that
would be helpful rather than to point out any sort of mistake.  But
since you ask, I think the mistake you made was jumping to a
conclusion without looking carefully enough at the problem.

Back to comp.lang.c | Previous | NextNext in thread | Find similar


Thread

Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-01 18:54 -0800
  Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-01 19:36 -0800

csiph-web