🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3825

Re: unreliable structures?

#3825
From: Paul Eggert
Date: Wed, 23 Aug 1995 14:21
35 lines
2021 bytes
Here's my guess as to what Ben Wing's question boils down to.  Given:

	struct s { int a, b; } x;
	void f() { x = (struct s) { a: x.b, b: x.a }; }

Must `f' swap x.a and x.b, or can the implementation rely on the
``overlapping move'' clause of the standard and yield undefined behavior?

wing@netcom.com (Ben Wing) writes:

>Chris claims that the ANSI C standard does not actually forbid this
>bogosity from happening, or at least is not explicit about this.

Strictly speaking, Chris is correct, because the above example uses
extensions that aren't in the C Standard.  However, the extensions do
appear in the C9X drafts (see
<ftp://ftp.dmk.com/DMK/sc22wg14/c9x/compound-literals/> and
<ftp://ftp.dmk.com/DMK/sc22wg14/c9x/extended-initializers/>).
The 1995-05-20 draft of the compound literals proposal says:

	The value of the compound literal is that of an unnamed object
	initialized by the initializer list.  The object has static storage
	duration if and only if the postfix expression occurs in a context
	other than within the body of a function; otherwise, it has automatic
	storage duration associated with the enclosing block.

This means that the compound literal `(struct s) { a: x.b, b: x.a }'
evaluates to the value of an unnamed object, so the ``overlapping
move'' clause does not apply.  So, as far as the latest public C9X
drafts are concerned, the above example has well-defined semantics.

That being said, I'm not sure I've boiled down Wing's example to the
right question; it's possible that Chris Torek is objecting to some
other part of Wing's example, which is much more complicated than
my boiled-down version.
Technical Details
Message-ID: <41fdhb$7nd@light.twinsun.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!twinsun!not-for-mail
References: <wingDDr1ys.CG1@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!twinsun!not-for-mail
From: eggert@twinsun.com (Paul Eggert)
Newsgroups: comp.std.c
Subject: Re: unreliable structures?
Date: 23 Aug 1995 07:21:31 -0700
Organization: Twin Sun Inc, El Segundo, CA, USA
Message-ID: <41fdhb$7nd@light.twinsun.com>
References: <wingDDr1ys.CG1@netcom.com>
NNTP-Posting-Host: light.twinsun.com