Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Nick Bowler <nbowler@draconx.ca> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Unsequenced Side Effects on the Same Union |
| Date | 2013-01-16 14:55 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <kd6f0b$fh4$1@dont-email.me> (permalink) |
| References | <kd570b$mvc$1@dont-email.me> |
On Tue, 15 Jan 2013 22:32:27 -0500, Shao Miller wrote:
> #include <stdio.h>
>
> void func1(void * vp1, void * vp2) {
> int * ip;
> double * dp;
>
> /* Populate ip and dp? */
> if (!vp1 && !vp2) {
> func1(&ip, &dp);
>
> /*
> * 6.5p2: Unsequenced side effects
> * on the same... Scalar?
> */
> printf("%f\n", (*ip = 42) + (*dp = 3.14));
> }
>
> /* Self-called? */
> if (vp1 && vp2) {
> /* Aliasing shoved down here */
> static union {
> int i;
> double d;
> } u;
> *(int **) vp1 = &u.i;
> *(double **) vp2 = &u.d;
> }
> }
>
> int main(void) { func1(NULL, NULL); return 0; }
>
> Sorry all, I'm puzzled... This surely yields undefined behaviour, but
> why, in C11? 6.5p2 changed from that of C99. Is it because one of the
> '+' operands could establish an effective type before the other?
I have a feeling that when the authors wrote "scalar object" in n1570
6.5p2 they had something specific in mind, but the term does not appear
to be defined anywhere in the standard. The term also is not in the
index. Perhaps this was corrected in the final standard which I do not
have a copy of.
"Scalar object" is also used in 5.1.2.4p14, where context suggests that
it at least excludes bit-fields. It appears again in 5.1.2.4p19 with
context suggesting that it includes objects with atomic types. It is
also used a couple times in Annex K, with context suggesting that it
does not include objects that are elements of arrays.
At the very least, the undefined term "scalar object" appears to
have absolutely nothing to do with the confusingly similarly-named
(and actually defined) "scalar type". Fun.
Cheers,
Nick
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unsequenced Side Effects on the Same Union Shao Miller <sha0.miller@gmail.com> - 2013-01-15 22:32 -0500
Re: Unsequenced Side Effects on the Same Union Nick Bowler <nbowler@draconx.ca> - 2013-01-16 14:55 +0000
Re: Unsequenced Side Effects on the Same Union Shao Miller <sha0.miller@gmail.com> - 2013-01-16 10:53 -0500
Re: Unsequenced Side Effects on the Same Union James Kuyper <jameskuyper@verizon.net> - 2013-01-16 11:04 -0500
Re: Unsequenced Side Effects on the Same Union Nick Bowler <nbowler@draconx.ca> - 2013-01-16 20:56 +0000
Re: Unsequenced Side Effects on the Same Union Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-17 13:21 -0800
Re: Unsequenced Side Effects on the Same Union Shao Miller <sha0.miller@gmail.com> - 2013-01-17 17:50 -0500
Re: Unsequenced Side Effects on the Same Union Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-18 11:25 -0800
Re: Unsequenced Side Effects on the Same Union Shao Miller <sha0.miller@gmail.com> - 2013-01-18 15:07 -0500
csiph-web