Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Repeated types in union |
| Date | 2012-01-25 13:46 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <kfnsjj35uc8.fsf@x-alumni2.alumni.caltech.edu> (permalink) |
| References | <jc0l4g$cvr$1@speranza.aioe.org> <7mg8e719tetfp8bhkrk4t9anr9nb88flhp@4ax.com> <47388767-a0bc-47f8-83e0-514750c4fdbb@z1g2000vbx.googlegroups.com> <4EE6515E.40402@loria.fr> <50195a8d-9e94-4c33-835c-eed3eea0c0b6@y12g2000vba.googlegroups.com> |
"christian.bau" <christian.bau@cbau.wanadoo.co.uk> writes: > On Dec 12, 7:09 pm, Jens Gustedt <jens.gust...@loria.fr> wrote: > >> If I remember correctly the aliasing rules state that the compiler is >> allowed to assume that a and b (insided the function) point to different >> objects because they are of different types. Thus in the second >> assignment to *a the compiler can assume that *a is still 3 and store 5 >> in place. > > You are right. On the other hand, footnote 82 says: > > "If the member used to access the contents of a union object is not > the same as the member last used to store a value in the object, the > appropriate part of the object representation of the value is > reinterpreted as an object representation in the new type as described > in 6.2.6 (a process sometimes called "type punning"). " > > Which is a direct contradiction. I am assuming that the rules for > union members apply in the same way whether the compiler knows that it > is accessing different members of the same union or not. It isn't a contradiction because of how the objects are accessed is different in the two cases. When a member is accessed (ie, using '.' or '->') the effective type is determined by the declared type of the member. When an object is accessed through a pointer, there is no declared type, so the rule for what the effective type is or must be is different.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Repeated types in union Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2011-12-10 22:06 +0000
Re: Repeated types in union Jens Gustedt <jens.gustedt@loria.fr> - 2011-12-11 00:11 +0100
Re: Repeated types in union Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-10 18:14 -0500
Re: Repeated types in union Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2011-12-12 20:09 +0000
Re: Repeated types in union Jens Gustedt <jens.gustedt@loria.fr> - 2011-12-12 23:45 +0100
Re: Repeated types in union Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-12 19:48 -0500
Re: Repeated types in union "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-12-13 15:17 -0800
Re: Repeated types in union Keith Thompson <kst-u@mib.org> - 2011-12-13 15:29 -0800
Re: Repeated types in union James Kuyper <jameskuyper@verizon.net> - 2011-12-13 18:30 -0500
Re: Repeated types in union Noob <root@127.0.0.1> - 2011-12-14 17:40 +0100
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:28 -0800
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 15:04 -0800
Re: Repeated types in union ralph <nt_consulting64@yahoo.net> - 2011-12-12 14:50 -0600
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 14:53 -0800
Re: Repeated types in union Barry Schwarz <schwarzb@dqel.com> - 2011-12-10 22:04 -0800
Re: Repeated types in union "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-12-12 09:49 -0800
Re: Repeated types in union Jens Gustedt <jens.gustedt@loria.fr> - 2011-12-12 20:09 +0100
Re: Repeated types in union "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-12-13 15:10 -0800
Re: Repeated types in union Jens Gustedt <jens.gustedt@loria.fr> - 2011-12-14 00:24 +0100
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:46 -0800
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:42 -0800
Re: Repeated types in union Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:36 -0800
csiph-web