Re: Regarding assignment to struct

Liste des GroupesRevenir à cl c 
Sujet : Re: Regarding assignment to struct
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 04. May 2025, 21:20:10
Autres entêtes
Organisation : None to speak of
Message-ID : <87bjs8p1qd.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
On 5/3/25 20:37, Keith Thompson wrote:
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.
>
"When a value is stored in an object of structure or union type,
including in a member object, the bytes of the object representation
that correspond to any padding bytes take unspecified values.56)"
(6.2.6.1p6).
>
That refers to footnote 56, which says "Thus, for example, structure
assignment need not copy any padding bits."

Yes, that's what I missed.

It's interesting that the footnote refers to padding *bits* rather than
padding *bytes*.  I presume this was unintentional.

Padding bytes are bytes within a structure or union that are not part of
any member.  Padding *bits* are bits within the representation of an
integer type that do not convert to an object's value.  I believe it's
true that integer padding bits need not be copied by assignment (for
example, they might be normalized to 0 for some reason), but that's
not specific to struct or union assignment.

There can also be bits within a struct or union representation that are
adjacent to a bit-field and do not contribute to any value.  As far as I
know, there's no name for those bits.

[snip]

Finally, why would you care?
>
The fact that an implementation does not have to do the equivalent of
memcpy() to perform a struct copy means that successful assignment
cannot be checked by using memcmp().

Are you referring to checking whether an assignment was performed
or not, due to uncertainty about what the program has done?  If you
mean doing an assignment and then checking whether it succeeded,
I can't think of a context where that makes sense.

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

Date Sujet#  Auteur
2 May 25 * Regarding assignment to struct84Lew Pitcher
2 May 25 +- Re: Regarding assignment to struct1Keith Thompson
2 May 25 +* Re: Regarding assignment to struct13Barry Schwarz
2 May 25 i`* That depends... (Was: Regarding assignment to struct)12Kenny McCormack
3 May 25 i `* Re: That depends... (Was: Regarding assignment to struct)11Lew Pitcher
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1Lawrence D'Oliveiro
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1Janis Papanagnou
3 May 25 i  +* Re: That depends... (Was: Regarding assignment to struct)5Kaz Kylheku
3 May 25 i  i+* Re: That depends... (Was: Regarding assignment to struct)3Kaz Kylheku
5 May 25 i  ii`* Re: That depends... (Was: Regarding assignment to struct)2Janis Papanagnou
5 May 25 i  ii `- Re: That depends... (Was: Regarding assignment to struct)1Kaz Kylheku
4 May 25 i  i`- Re: That depends... (Was: Regarding assignment to struct)1Tim Rentsch
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1James Kuyper
4 May 25 i  `* Re: That depends... (Was: Regarding assignment to struct)2Tim Rentsch
4 May 25 i   `- Re: That depends... (Was: Regarding assignment to struct)1Lew Pitcher
2 May 25 +* Re: Regarding assignment to struct2Waldek Hebisch
3 May 25 i`- Re: Regarding assignment to struct1Lew Pitcher
3 May 25 +* Re: Regarding assignment to struct51Andrey Tarasevich
3 May 25 i+* Re: Regarding assignment to struct9Lawrence D'Oliveiro
4 May 25 ii`* Re: Regarding assignment to struct8Keith Thompson
4 May 25 ii `* Re: Regarding assignment to struct7James Kuyper
4 May 25 ii  +- Re: Regarding assignment to struct1Kenny McCormack
4 May 25 ii  +- Re: Regarding assignment to struct1David Brown
4 May 25 ii  `* Re: Regarding assignment to struct4Keith Thompson
5 May 25 ii   +- Re: Regarding assignment to struct1James Kuyper
5 May 25 ii   +- Re: Regarding assignment to struct1Keith Thompson
6 May 25 ii   `- Re: Regarding assignment to struct1Tim Rentsch
3 May 25 i+- Re: Regarding assignment to struct1Lawrence D'Oliveiro
4 May 25 i`* Re: Regarding assignment to struct40Tim Rentsch
5 May 25 i `* Re: Regarding assignment to struct39Andrey Tarasevich
5 May 25 i  +* Re: Regarding assignment to struct16Michael S
5 May 25 i  i+* Re: Regarding assignment to struct14Andrey Tarasevich
5 May 25 i  ii`* Re: Regarding assignment to struct13Michael S
5 May 25 i  ii +- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  ii `* Re: Regarding assignment to struct11Andrey Tarasevich
5 May 25 i  ii  +* Re: Regarding assignment to struct2Michael S
6 May 25 i  ii  i`- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  ii  `* Re: Regarding assignment to struct8Keith Thompson
6 May 25 i  ii   +* Re: Regarding assignment to struct2Tim Rentsch
6 May 25 i  ii   i`- Re: Regarding assignment to struct1Keith Thompson
6 May 25 i  ii   +- Re: Regarding assignment to struct1David Brown
6 May 25 i  ii   `* Re: Regarding assignment to struct4Waldek Hebisch
6 May 25 i  ii    +* Re: Regarding assignment to struct2David Brown
7 May 25 i  ii    i`- Re: Regarding assignment to struct1David Brown
6 May 25 i  ii    `- Re: Regarding assignment to struct1Keith Thompson
5 May 25 i  i`- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  +* Re: Regarding assignment to struct4Keith Thompson
5 May 25 i  i`* Re: Regarding assignment to struct3Andrey Tarasevich
8 May 25 i  i `* Re: Regarding assignment to struct2Tim Rentsch
8 May 25 i  i  `- Re: Regarding assignment to struct1David Brown
5 May 25 i  +* Re: Regarding assignment to struct15Keith Thompson
5 May 25 i  i+* Re: Regarding assignment to struct6Michael S
5 May 25 i  ii+- Re: Regarding assignment to struct1Kenny McCormack
5 May 25 i  ii+* Re: Regarding assignment to struct3Keith Thompson
5 May 25 i  iii`* Re: Regarding assignment to struct2Kaz Kylheku
6 May 25 i  iii `- Re: Regarding assignment to struct1Tim Rentsch
6 May 25 i  ii`- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  i`* Re: Regarding assignment to struct8Tim Rentsch
5 May 25 i  i `* Re: Regarding assignment to struct7Keith Thompson
6 May 25 i  i  `* Re: Regarding assignment to struct6Nick Bowler
6 May 25 i  i   `* Re: Regarding assignment to struct5Keith Thompson
7 May 25 i  i    `* Re: Regarding assignment to struct4Nick Bowler
7 May 25 i  i     +* Re: Regarding assignment to struct2Keith Thompson
8 May 25 i  i     i`- Re: Regarding assignment to struct1Nick Bowler
8 May 25 i  i     `- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  +* Re: Regarding assignment to struct2Tim Rentsch
5 May 25 i  i`- Re: Regarding assignment to struct1David Brown
12 May 25 i  `- Re: Regarding assignment to struct1NotAorB
3 May 25 +* Re: Regarding assignment to struct8David Brown
5 May 25 i`* Re: Regarding assignment to struct7Muttley
5 May 25 i +- Re: Regarding assignment to struct1David Brown
5 May 25 i `* Re: Regarding assignment to struct5Keith Thompson
6 May 25 i  +- Re: Regarding assignment to struct1Muttley
6 May 25 i  +* Re: Regarding assignment to struct2David Brown
6 May 25 i  i`- Re: Regarding assignment to struct1Muttley
6 May 25 i  `- Re: Regarding assignment to struct1Michael S
4 May 25 +* Re: Regarding assignment to struct6Richard Damon
4 May 25 i`* Re: Regarding assignment to struct5Michael S
4 May 25 i +* Re: Regarding assignment to struct2Lawrence D'Oliveiro
4 May 25 i i`- Re: Regarding assignment to struct1David Brown
6 May 25 i +- Re: Regarding assignment to struct1Tim Rentsch
12 May 25 i `- Re: Regarding assignment to struct1Rosario19
4 May 25 +- Re: Regarding assignment to struct1Tim Rentsch
4 May 25 `- Re: Regarding assignment to struct1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal