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


Groups > comp.lang.c > #104404

Re: modifying local const variable run time

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: modifying local const variable run time
Date 2017-02-22 21:55 +0000
Organization A noiseless patient Spider
Message-ID <87h93l7ux1.fsf@bsb.me.uk> (permalink)
References (3 earlier) <20170222173450.4fe314b3c852b242bb2dc35a@gmail.com> <idgrac1th0dk144r2niokdbstdc51ct8s9@4ax.com> <20170222175222.30c839c809d4d6c6b005274f@gmail.com> <o8kteq$hj3$1@dont-email.me> <35ac8d68-6fc3-4bc7-811d-2ab8a893c215@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com writes:
<snip>
> There is another case where "const" is relevant: if a block starts with a
> declaration like
>
>    void const * const restrict arbitraryName = &something;
>
> a compiler would be entitled to assume that the object in question will
> not be modified by any means during the execution of that block, even if
> the object in question is not const-qualified and might perfectly
> legitimately be modified *at times when the block isn't being executed*.
> That may facilitate optimizations that would not otherwise be possible,
> though it would seem like a directive that was equivalent to such a
> construct but didn't require defining a dummy variable might be
> clearer.

Is this an example of undefined behaviour you are describing:

  int main(void)
  {
      int something = 1;
      void const * const restrict arbitraryName = &something;
      something = 0;
      return something;
  }

If so, can you say why it's undefined?  I can see only one lvalue being
used (something) and a pointer to it (&something) is not an expression
based on arbitraryName.  Have I misunderstood?

-- 
Ben.

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


Thread

modifying local const variable run time rahul.dev.agg@gmail.com - 2017-02-22 06:39 -0800
  Re: modifying local const variable run time GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-22 16:06 +0100
    Re: modifying local const variable run time rahul.dev.agg@gmail.com - 2017-02-22 07:26 -0800
      Re: modifying local const variable run time David Brown <david.brown@hesbynett.no> - 2017-02-22 16:31 +0100
        Re: modifying local const variable run time rahul.dev.agg@gmail.com - 2017-02-22 07:43 -0800
          Re: modifying local const variable run time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-22 16:06 +0000
      Re: modifying local const variable run time James Kuyper <jameskuyper@verizon.net> - 2017-02-22 11:13 -0500
      Re: modifying local const variable run time supercat@casperkitty.com - 2017-02-22 08:34 -0800
        Re: modifying local const variable run time David Brown <david.brown@hesbynett.no> - 2017-02-22 23:03 +0100
      Re: modifying local const variable run time GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-22 17:34 +0100
        Re: modifying local const variable run time Robert Wessel <robertwessel2@yahoo.com> - 2017-02-22 10:52 -0600
          Re: modifying local const variable run time GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-22 17:52 +0100
            Re: modifying local const variable run time Keith Thompson <kst-u@mib.org> - 2017-02-22 09:33 -0800
            Re: modifying local const variable run time James Kuyper <jameskuyper@verizon.net> - 2017-02-22 15:50 -0500
              Re: modifying local const variable run time supercat@casperkitty.com - 2017-02-22 13:13 -0800
                Re: modifying local const variable run time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-22 21:55 +0000
                Re: modifying local const variable run time supercat@casperkitty.com - 2017-02-22 14:43 -0800
        Re: modifying local const variable run time Keith Thompson <kst-u@mib.org> - 2017-02-22 09:23 -0800
          Re: modifying local const variable run time GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-22 18:32 +0100
            Re: modifying local const variable run time Keith Thompson <kst-u@mib.org> - 2017-02-22 09:50 -0800
              Re: modifying local const variable run time David Brown <david.brown@hesbynett.no> - 2017-02-22 23:07 +0100
                Re: modifying local const variable run time Keith Thompson <kst-u@mib.org> - 2017-02-22 15:20 -0800
                Re: modifying local const variable run time David Brown <david.brown@hesbynett.no> - 2017-02-23 09:50 +0100
  Re: modifying local const variable run time James Kuyper <jameskuyper@verizon.net> - 2017-02-22 10:16 -0500
  Re: modifying local const variable run time Keith Thompson <kst-u@mib.org> - 2017-02-22 09:17 -0800

csiph-web