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


Groups > comp.lang.c > #72034

Re: the language (and the role of Undefined Behavior therein)

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: the language (and the role of Undefined Behavior therein)
Date 2015-10-06 11:04 +0100
Organization A noiseless patient Spider
Message-ID <87vbak9uto.fsf@bsb.me.uk> (permalink)
References (8 earlier) <musvis$1j0$1@speranza.aioe.org> <877fn1lc3f.fsf@bsb.me.uk> <muu4qu$pqj$1@speranza.aioe.org> <87wpv1jh23.fsf@bsb.me.uk> <muus8j$k62$1@speranza.aioe.org>

Show all headers | View raw


glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>
> (snip, I wrote)
>>> The standard does separate implementation defined and undefined,
>>> and I believe optimizers shouldn't do such tricks for the former.
>  
>> Yes.  It is that latter case -- undefined behaviour being exploited for
>> optimisation -- that is at issue.
>  
>>> As for what the hardware might do, consider:
>
> (snip on tagged hardware)
>
>> I'm not sure how this information (not new to me BTW!) fits in.  Are you
>> agreeing, disagreeing, what?  I think supercat would be fine with an
>> exception in cases where that is what the hardware does.
>
> The hardware can refuse to let you look at the bits in a different way.
> Storing a (float) into a union and fetching an (int) would be a
> hardware exception.  (As it is in Java.)

Yes, I know, but that's not the point.  Exposing the hardware's
behaviour (provided it can be made conforming) is fine.  supercat's
issue is with the language rules.

> (snip)
>
>>> On many systems, the hardware trap for unaligned access if fatal,
>>> so software can assume that it didn't happen.
>  
>> It can't know (in general) that the access is unaligned.  But I don't
>> think this is a hardware issue -- it's about a C language rule.
>  
>>> But yes, I mostly disagree with optimizers assuming some things
>>> can't happen and optimize on that assumption.
>  
>> The C rule says it can't happen, even on machines where the 
>> hardware is happy.  That's the point at issue.
>
> Yes, I also agree that optimizers shouldn't do that.

But I don't!  I was simply trying to point out what supercat was
saying.  C has had it's effective type rules for a long time and it's
not that hard to program round them.  You can also rely on the fact that
some of these accesses are undefined if your implementation promises a
certain behaviour.  I don't know of any that do, but there might well be
small-system compilers that promise to interpret *(T *)p in a literal
way.

<snip>
-- 
Ben.

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


Thread

Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-09-29 15:48 -0700
  Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 16:57 -0700
    Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-04 19:48 -0700
      Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 04:50 +0000
        Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 13:43 +0100
          Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 15:26 +0000
            Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 19:39 +0100
              Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 13:32 -0700
              Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 22:06 +0000
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 16:08 -0700
                Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-06 11:04 +0100
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 08:06 -0700
                Re: the language (and the role of Undefined Behavior therein) Rosario19 <Ros@invalid.invalid> - 2015-10-06 18:14 +0200
                Re: the language (and the role of Undefined Behavior therein) Rosario19 <Ros@invalid.invalid> - 2015-10-06 18:54 +0200
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 11:20 -0700
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 10:00 -0700
                Re: the language (and the role of Undefined Behavior therein) David Thompson <dave.thompson2@verizon.net> - 2015-10-31 06:44 -0400
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-31 11:08 -0700
                Re: the language (and the role of Undefined Behavior therein) Keith Thompson <kst-u@mib.org> - 2015-10-31 13:53 -0700
                Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-31 14:06 -0700
          Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 09:28 -0700
          Re: the language (and the role of Undefined Behavior therein) Keith Thompson <kst-u@mib.org> - 2015-10-05 11:20 -0700
            Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 20:13 +0100
              Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-12 09:29 -0700
      Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-12 10:32 -0700
        Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-12 12:23 -0700
        Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-12 14:42 -0700
        Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-14 09:10 -0700
          Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-19 16:11 -0700

csiph-web