Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #128159
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: Does simple inheritance break strict-aliasing rule |
| Date | Wed, 21 Mar 2018 10:20:13 -0700 |
| Organization | None to speak of |
| Lines | 44 |
| Message-ID | <lnwoy5pcqa.fsf@kst-u.example.com> (permalink) |
| References | <p8tbjk$mku$1@dont-email.me> <87h8p9tofh.fsf@bsb.me.uk> <f8e43b88-b58c-4962-a582-282992b5de58@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="8fef62c5babeabfae505a3b4aebc529d"; logging-data="23638"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180O0noFlKFJsYLbpgxNFkN" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:qyHz4seLvbnGy7205Qf/cBwpOzY= sha1:/DRQpNnLZwpGaoPB/PR2rtlnRik= |
| Xref | csiph.com comp.lang.c:128159 |
Show key headers only | View raw
supercat@casperkitty.com writes:
> On Wednesday, March 21, 2018 at 10:54:06 AM UTC-5, Ben Bacarisse wrote:
>> C has no "strict-aliasing rule". It has what are called effective type
>> rules and these say that you can't access an object of one type though
>> an lvalue expression of another type. That's a gross simplification of
>> course, but none of the details are in play here. Provided s->type is
>> never equal RECT when s is not, in fact, pointing at the Shape inside a
>> Rect, then you are not breaking C's rules when you write r->whatever.
>
> A literal reading of the rules would indicate that given:
>
> struct foo {int x; } *p;
>
> the lvalue "p->x" has type "int". As such, it may be used to access any
> object whose type is simply "int", but may not be used to access any object
> of type "struct foo".
Of course p->x is of type int.
> The rules would make a lot of sense if "p->x" were regarded for purposes of
> 6.5p7 as an lvalue of type "struct foo"
No, it would make no sense at all to treat p->x as an lvalue of type
struct foo. Would you want this to be legal?
struct foo {int x; } *p;
struct foo obj;
// assume reasonable initializations
p->x = obj;
If p->x is regarded as an lvalue of type struct foo, why would that last
assignment not be legal?
*p is of type struct foo because p is defined as an object of type
struct foo*. p->x is of type int because x is defined as a member of
type int.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Does simple inheritance break strict-aliasing rule pozz <pozzugno@gmail.com> - 2018-03-21 11:19 +0100
Re: Does simple inheritance break strict-aliasing rule Thiago Adams <thiago.adams@gmail.com> - 2018-03-21 05:37 -0700
Re: Does simple inheritance break strict-aliasing rule Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-21 07:02 -0700
Re: Does simple inheritance break strict-aliasing rule James Kuyper <jameskuyper@verizon.net> - 2018-03-21 10:31 -0400
Re: Does simple inheritance break strict-aliasing rule supercat@casperkitty.com - 2018-03-21 09:38 -0700
Re: Does simple inheritance break strict-aliasing rule Nick Bowler <nbowler@draconx.ca> - 2018-03-21 14:46 +0000
Re: Does simple inheritance break strict-aliasing rule supercat@casperkitty.com - 2018-03-21 08:18 -0700
Re: Does simple inheritance break strict-aliasing rule Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-21 23:23 -0700
Re: Does simple inheritance break strict-aliasing rule Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-21 15:53 +0000
Re: Does simple inheritance break strict-aliasing rule supercat@casperkitty.com - 2018-03-21 09:30 -0700
Re: Does simple inheritance break strict-aliasing rule Keith Thompson <kst-u@mib.org> - 2018-03-21 10:20 -0700
Re: Does simple inheritance break strict-aliasing rule supercat@casperkitty.com - 2018-03-21 10:54 -0700
Re: Does simple inheritance break strict-aliasing rule Keith Thompson <kst-u@mib.org> - 2018-03-21 11:48 -0700
Re: Does simple inheritance break strict-aliasing rule supercat@casperkitty.com - 2018-03-21 14:28 -0700
Re: Does simple inheritance break strict-aliasing rule Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-21 21:39 +0000
csiph-web