Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #1845

Re: Unsequenced Side Effects on the Same Union

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.std.c
Subject Re: Unsequenced Side Effects on the Same Union
Date 2013-01-16 11:04 -0500
Organization A noiseless patient Spider
Message-ID <50F6CF92.4090803@verizon.net> (permalink)
References <kd570b$mvc$1@dont-email.me> <kd6f0b$fh4$1@dont-email.me>

Show all headers | View raw


On 01/16/2013 09:55 AM, Nick Bowler wrote:
> 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.

A "scalar object" should simply mean an "object of scalar type".

> "Scalar object" is also used in 5.1.2.4p14, where context suggests that
> it at least excludes bit-fields. ...

You're right, and I think that's a mistake. All bit-fields with non-zero
widths are objects which have scalar types.

> ...  It appears again in 5.1.2.4p19 with
> context suggesting that it includes objects with atomic types. ...

Yes, any object with an atomic scalar type would qualify.

>  ... It is
> also used a couple times in Annex K, with context suggesting that it
> does not include objects that are elements of arrays.

Yes, array types are not scalar.

> 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.

The only problem I can see with my interpretation is 5.1.2.4p14, which I
think was a mistake. Do you have any other reason for believing that a
"scalar object" means anything other than an "object with scalar type"?

Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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