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


Groups > comp.lang.c > #120634

Re: const and the C type system

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: const and the C type system
Date 2017-10-01 11:38 +1300
Message-ID <f3aknoFepgcU3@mid.individual.net> (permalink)
References (5 earlier) <fKQzB.1787364$DB.699792@fx04.am4> <f3ac5mFepgcU1@mid.individual.net> <fsTzB.576003$wU.46957@fx36.am4> <f3afj1FepgcU2@mid.individual.net> <0KUzB.1232839$tN5.944416@fx27.am4>

Show all headers | View raw


On 10/ 1/17 11:17 AM, bartc wrote:
> On 30/09/2017 22:10, Ian Collins wrote:
>> On 10/ 1/17 09:50 AM, bartc wrote:
>>> On 30/09/2017 21:12, Ian Collins wrote:
>>>> On 10/ 1/17 06:44 AM, bartc wrote:
>>>
>>>> There's nothing complicated about C++'s constexpr, it's just a more
>>>> versatile const.
>>>
>>> /That/ makes it more complicated. Being less versatile is better!
>>
>> Not if you want versatility...
>
> We're talking about attaching a name to a constant value.
>
> That's ... it.
>
> What more do you need? If you want everthing that const or constexpr can
> do, then use those.

In the case of the former, without adding to the C vocabulary.  Why go 
for something half-arsed when you can have the real thing?

>>> We're talking about different things then. My idea of a constant has no
>>> notion of storage associated with it. It's the equivalent of an
>>> immediate value in assembly.
>>
>> Why be so restrictive?  If I write
>>
>> const int abc = 100;
>>
>> and don't take the address of abc, there won't be any storage associated
>> with abc.
>
> With certain compiler and at certain settings.

With any usable compiler, of if C had constexpr, with any compiler.

> But why even entertain the notion of taking its address?

Because you might want to pass it to a function which takes a pointer?

> Use:
>
>     constant int abc = 100;
>
> and it will be IMPOSSIBLE to take the address, any more than you can
> take the address of a number using &100.
>
> It will also be IMPOSSIBLE to forget to initialise it as is possible
> with const:
>
>     const int abc;

With C++'s const rules, you also can't forget.

> You are also pretty much guaranteed that its value will be implemented
> as an immediate value, rather than depend on the vagaries of compiler
> and optimisation level.
>
> With C's current rules, my named constant could be used for for non-VLA
> array bounds and for case labels in a way that is not allowed for const
> variables.

With C++'s const rules, you can use const in those cases.

> And it makes it much easier for simple, lightweight C compilers (SubC
> SmallC, PicoC etc) to generate code that is a little more efficient as
> there is no need for ANY analysis to determine if that value could
> conceivably change; IT CAN'T.

With C++'s const rules, it can't.

> In other words, this idea is a complete no-brainer. Yet no one likes it
> (except perhaps Thiago Adams but he has more complicated things on his
> mind).

So is adding C++'s const rules to C!

-- 
Ian

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


Thread

const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-28 19:51 -0700
  Re: const and the C type system Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-09-28 21:32 -0600
    Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 05:45 -0700
      Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-29 14:05 +0100
        Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 06:17 -0700
    Re: const and the C type system asetofsymbols@gmail.com - 2017-10-01 22:35 -0700
  Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-09-29 10:59 +0200
    Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 06:06 -0700
      Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-29 14:24 +0100
        Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 06:52 -0700
          Re: const and the C type system jameskuyper@verizon.net - 2017-09-29 09:17 -0700
            Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 10:50 -0700
              Re: const and the C type system jameskuyper@verizon.net - 2017-09-29 11:06 -0700
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 11:27 -0700
          Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-30 13:13 -0700
            Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-30 13:31 -0700
        Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-09-29 09:10 -0700
          Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-29 18:33 +0100
          Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 11:10 -0700
        Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-09-30 08:29 +1300
        Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-09-30 18:48 +0200
          Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-30 18:44 +0100
            Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-01 09:12 +1300
              Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-30 21:50 +0100
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-01 10:10 +1300
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-30 23:17 +0100
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-01 11:38 +1300
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 00:44 +0100
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-01 14:33 +1300
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 10:42 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 19:58 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 21:30 +0100
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-02 17:48 +1300
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 11:14 +0100
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-02 23:22 +1300
                Re: const and the C type system Richard Damon <Richard@Damon-Family.org> - 2017-10-01 13:58 -0400
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 18:20 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 18:41 +0100
                Re: const and the C type system supercat@casperkitty.com - 2017-10-01 12:03 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 23:05 +0200
                Re: const and the C type system supercat@casperkitty.com - 2017-10-01 15:58 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-02 09:56 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 00:24 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-02 12:20 +0200
                Re: const and the C type system Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-10-02 06:03 -0700
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-02 06:34 -0700
                Re: const and the C type system supercat@casperkitty.com - 2017-10-02 23:38 -0700
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-01 13:03 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 23:12 +0200
                Re: const and the C type system supercat@casperkitty.com - 2017-10-01 11:12 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 13:48 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 14:13 +0100
                Re: const and the C type system supercat <flatfinger@casperkitty.com> - 2017-10-01 10:32 -0700
              Re: const and the C type system supercat@casperkitty.com - 2017-09-30 13:52 -0700
            Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-09-30 13:35 -0700
              Re: const and the C type system bartc <bc@freeuk.com> - 2017-09-30 21:58 +0100
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 12:03 +0100
              Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-30 14:00 -0700
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-09-30 15:33 -0700
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-01 12:45 -0700
            Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 13:13 +0200
              Re: const and the C type system Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-10-01 05:22 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 20:06 +0200
                Re: const and the C type system supercat@casperkitty.com - 2017-10-01 12:16 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 21:01 +0100
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-01 13:21 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 21:50 +0100
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-02 05:35 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 14:01 +0100
                Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-02 06:29 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 15:19 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 23:19 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 22:33 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-02 00:10 +0200
              Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 14:13 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-01 22:46 +0200
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 21:57 +0100
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-10-01 14:09 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-01 23:54 +0100
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-10-01 19:12 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 11:36 +0100
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-02 12:45 +0200
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-10-02 09:40 -0700
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 19:33 +0100
                Re: const and the C type system scott@slp53.sl.home (Scott Lurndal) - 2017-10-02 19:09 +0000
                Re: const and the C type system Ian Collins <ian-news@hotmail.com> - 2017-10-03 08:12 +1300
                Re: const and the C type system bartc <bc@freeuk.com> - 2017-10-02 20:30 +0100
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-10-02 12:37 -0700
                Re: const and the C type system jadill33@gmail.com - 2017-10-02 12:49 -0700
                Re: const and the C type system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-10-06 20:47 +0000
                Re: const and the C type system Keith Thompson <kst-u@mib.org> - 2017-10-06 15:41 -0700
                Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-10-02 12:42 +0200
              Re: const and the C type system Gareth Owen <gwowen@gmail.com> - 2017-10-01 21:18 +0100
          Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-30 12:22 -0700
      Re: const and the C type system David Brown <david.brown@hesbynett.no> - 2017-09-30 18:44 +0200
    Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 07:01 -0700
      Re: const and the C type system Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 20:18 +0100
        Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-09-29 12:40 -0700
          Re: const and the C type system Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 21:28 +0100
  Re: const and the C type system fir <profesor.fir@gmail.com> - 2017-09-29 08:21 -0700
    Re: const and the C type system fir <profesor.fir@gmail.com> - 2017-09-29 08:38 -0700
  Re: const and the C type system John Bode <jfbode1029@gmail.com> - 2017-10-02 09:20 -0700
    Re: const and the C type system Thiago Adams <thiago.adams@gmail.com> - 2017-10-02 09:53 -0700
    Re: const and the C type system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-10-09 13:27 +0000

csiph-web