Sujet : Re: Regarding assignment to struct
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 04. May 2025, 01:37:28
Autres entêtes
Organisation : None to speak of
Message-ID : <87ikmhp5x3.fsf@nosuchdomain.example.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
Lawrence D'Oliveiro <
ldo@nz.invalid> writes:
On Sat, 3 May 2025 01:14:46 -0700, Andrey Tarasevich wrote:
Virtually every C project relies on assignment of structures.
Passing-returning structs by value might be more rare (although
perfectly valid and often appropriate too), but assignment...
assignment is used by everyone everywhere without even giving it a
second thought.
>
There is a caveat, to do with alignment padding: will this always have a
defined value?
I don't believe so. In a quick look, I don't see anything in
the standard that explicitly addresses this, but I believe that a
conforming implementation could implement structure assignment by
copying the individual members, leaving any padding in the target
undefined.
(A quibble about your wording: I don't believe padding has a "value"
as the term is used by the standard.)
The question is whether the "value" of a struct object consists
only of the values of its members. I'd say it does, but unless
I'm missing something the standard doesn't say so explicitly.
Finally, why would you care?e
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */