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


Groups > comp.lang.c > #112125

Re: Unexpected error on x[0] != y[0]

Newsgroups comp.lang.c
Date 2017-06-13 11:51 -0700
References (6 earlier) <28a9ed55-a6c8-4080-8d00-8ae18e5ef709@googlegroups.com> <e776acfc-d145-43b4-9c9c-be38ffcae8c1@googlegroups.com> <yLU%A.25623$G96.14968@fx26.am4> <ca9366c8-8956-47f9-88b6-cd4dfa2cbcc6@googlegroups.com> <qRV%A.139886$dE4.100852@fx36.am4>
Message-ID <2e301979-ea55-4eec-a3ac-df0d65617abc@googlegroups.com> (permalink)
Subject Re: Unexpected error on x[0] != y[0]
From supercat@casperkitty.com

Show all headers | View raw


On Tuesday, June 13, 2017 at 1:07:25 PM UTC-5, Bart wrote:
> The casts will do that in C. But there are other ways. This would be a 
> useful feature for C I think:
> 
> union {
>    int a;
>    int b[10];
>    float x;
> };

There are at least three useful meanings such a declaration could have:

1. Demand that a compiler recognize aliasing amoung common-initial-sequence
   members of all structure types listed therein without a programmer having
   to meet gcc's impractical requirement of using lvalues of that type.  This
   could slightly impede some optimizations, but most code that would need
   this feature would otherwise need to be written to block those phony
   "optimizations" via other means.

2. Demand that a compiler recognize aliasing among values of all types listed
   therein (though not necessarily transitively with members of other unions).
   That could be a major optimization hit in cases where code didn't require
   such aliasing, but if code does require such aliasing, correctness should
   trump speed.

3. Export all the union memebers as identifiers in their own right in the
   surrounding scope, assuming member x to be accessed as x, rather than as
   someUnion.x.

Meaning #3 is most analogous to the way declarations work within a nested
struct or union, but it might be better to say that a declaration like:

   struct { ... } auto x;
or
   struct foo auto x;

will create an object of that structure type in the current scope and
*also* create shorthand identifiers for each member thereof.  Such an
approach could be particularly useful when adapting existing code in
cases where it's necessary to be able to treat some variables as a unit
for purposes of things like fread/fwrite.

> This is legal syntax now, but doesn't do anything. The intention is that 
> in this form, it declares variables a, b and x that all occupy the same 
> location (the start of a 40-byte block).

I think it's should at least take care of meaning #1 (assuming the Standard
has any reason for saying "complete union type"), though the authors of
gcc and clang seem to think programmers should have to jump through hoops
to access useful semantics that had been available since C74.

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


Thread

Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-12 06:57 -0700
  Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-12 15:11 +0100
    Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-12 07:18 -0700
      Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-12 15:29 +0100
        Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-12 07:41 -0700
          Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-12 18:32 +0100
            Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-12 10:56 -0700
              Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 08:14 -0700
                Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-13 17:52 +0100
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 10:00 -0700
                Re: Unexpected error on x[0] != y[0] scott@slp53.sl.home (Scott Lurndal) - 2017-06-13 17:19 +0000
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 10:33 -0700
                Re: Unexpected error on x[0] != y[0] scott@slp53.sl.home (Scott Lurndal) - 2017-06-13 17:56 +0000
                Re: Unexpected error on x[0] != y[0] Gareth Owen <gwowen@gmail.com> - 2017-06-13 19:45 +0100
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 17:54 -0700
                Re: Unexpected error on x[0] != y[0] joel.rees@gmail.com - 2017-06-13 20:57 -0700
                Re: Unexpected error on x[0] != y[0] Gareth Owen <gwowen@gmail.com> - 2017-06-14 06:41 +0100
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-14 03:37 -0700
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-14 03:54 -0700
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 17:45 -0700
                Re: Unexpected error on x[0] != y[0] David Brown <david.brown@hesbynett.no> - 2017-06-14 08:49 +0200
                Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-13 19:07 +0100
                Re: Unexpected error on x[0] != y[0] Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-13 19:23 +0100
                Re: Unexpected error on x[0] != y[0] bartc <bc@freeuk.com> - 2017-06-13 22:30 +0100
                Re: Unexpected error on x[0] != y[0] Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-13 23:29 +0100
                Re: Unexpected error on x[0] != y[0] supercat@casperkitty.com - 2017-06-13 11:51 -0700
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-13 17:53 -0700
                Re: Unexpected error on x[0] != y[0] Reinhardt Behm <rbehm@hushmail.com> - 2017-06-14 13:34 +0800
                Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-14 03:24 -0700
                Re: Unexpected error on x[0] != y[0] David Brown <david.brown@hesbynett.no> - 2017-06-14 09:10 +0200
  Re: Unexpected error on x[0] != y[0] John Bode <jfbode1029@gmail.com> - 2017-06-12 07:26 -0700
    Re: Unexpected error on x[0] != y[0] "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-12 10:54 -0400
      Re: Unexpected error on x[0] != y[0] Keith Thompson <kst-u@mib.org> - 2017-06-12 09:23 -0700
    Re: Unexpected error on x[0] != y[0] Gareth Owen <gwowen@gmail.com> - 2017-06-12 19:05 +0100
  Re: Unexpected error on x[0] != y[0] Anton Shepelev <anton.txt@gmail.com> - 2017-06-12 17:29 +0300
  Re: Unexpected error on x[0] != y[0] Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-12 15:52 +0100
    Re: Unexpected error on x[0] != y[0] "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-12 08:31 -0700
  Re: Unexpected error on x[0] != y[0] joel.rees@gmail.com - 2017-06-13 22:09 -0700
    Re: Unexpected error on x[0] != y[0] Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-14 11:24 +0100

csiph-web