Deutsch   English   Français   Italiano  
<vv932r$37tbq$1@dont-email.me>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c
Subject: Re: Regarding assignment to struct
Date: Sun, 4 May 2025 21:08:43 -0400
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <vv932r$37tbq$1@dont-email.me>
References: <vv338b$16oam$1@dont-email.me> <vv4j9p$33vhj$1@dont-email.me>
 <vv66cu$hbtf$1@dont-email.me> <87ikmhp5x3.fsf@nosuchdomain.example.com>
 <vv6ng8$1410m$1@dont-email.me> <87bjs8p1qd.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 05 May 2025 03:08:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="052a7056b529303cb88fd94573b99fdb";
	logging-data="3405178"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+nD4Sw2XN3nVk+5sT1CzWuo2sqxAKKpMM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4euYALI6oA+gbJpcMbKGtPW/1bE=
In-Reply-To: <87bjs8p1qd.fsf@nosuchdomain.example.com>
Content-Language: en-US
Bytes: 2947

On 5/4/25 16:20, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>> On 5/3/25 20:37, Keith Thompson wrote:
....
>>> 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.
....
>>> 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.

Sorry, I didn't explain what I was thinking about in any detail. I've
seen code that allows a data structure to be modified by one section of
the code, and then periodically checks each object in that data
structure (including aggregate objects) to see whether it has been
modified by using memcmp() versus a saved copy. If so, it updated the
saved copy, including a timestamp when it was updated. If it weren't for
the need to keep track of the timestamp, it would always be simpler, and
not much slower, to always replace the saved copy, whether or not
there'd been a change.

I should have made it clear that I basically understand and agree with
your "why would you care" criticism. But it's part of my nature to look
for the edge cases where differences that ordinarily don't matter, could
matter.