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


Groups > comp.lang.c > #163225

Re: on the order of the const-keyword

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: on the order of the const-keyword
Date 2021-10-29 00:48 -0400
Organization A noiseless patient Spider
Message-ID <slfuf4$p46$1@dont-email.me> (permalink)
References <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me> <2a5589c2-89ac-4d77-a91d-508c00f75e43n@googlegroups.com> <86y26cle9j.fsf@levado.to>

Show all headers | View raw


On 10/28/21 11:07 PM, Meredith Montgomery wrote:
> "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes:
> 
>> On Thursday, October 28, 2021 at 12:26:09 PM UTC-4, Bart wrote:
>> ...
>>> 'const' (as well as short, int, long, float, double, even static and 
>>> typedef) can occur anywhere, in any combination, in the declaration of a 
>>> base type (what goes on the left before the first variable). 
>> ...
>>> However when applied to a pointer, then it must go after *.
>>
>> const char * p
>> char * const q;
>> char const * const r;
>>
>> are all permitted. p is a pointer to const char. q is a const pointer
>> to char. r is a const pointer to const char.
> 
> So the order does make a difference here.  I mean
> 
>  char const * r1
> 
> is not the same 
> 
>   char const * const r2
> 
> because r2 cannot point somewhere else but r1 can.  
> 
> Thank you.

The top-level grammar for such a declaration is

declaration-specifiers init-declarator-list opt ;

"char const" are the declaration specifiers, while the
init-declarator-list consists of a single declarator with no
initializer, which is "* const r2". "r2" is the identifier being
declared, and after any "*" in a declarator there may be additional type
qualifiers that are not part of the initial list of declaration
specifiers. Unlike the order of the declaration specifiers, the order of
the type qualifiers relative to the "*"s is VERY important.

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


Thread

on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-28 12:50 -0300
  Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 17:25 +0100
    Re: on the order of the const-keyword "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-10-28 10:10 -0700
      Re: on the order of the const-keyword Guillaume <message@bottle.org> - 2021-10-28 20:40 +0200
      Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:07 -0300
        Re: on the order of the const-keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-29 00:48 -0400
    Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 12:56 -0700
      Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 13:18 -0700
        Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 21:35 +0100
          Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 13:57 -0700
            Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 14:07 -0700
              Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 22:54 +0100
              Re: on the order of the const-keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-28 15:37 -0700
                Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-29 00:02 +0100
        Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-28 22:10 +0100
        Re: on the order of the const-keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-28 15:13 -0700
        Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:40 -0300
    Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-28 23:48 -0300
  Re: on the order of the const-keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-28 13:04 -0400
    Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:34 -0300
  Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 10:03 +0200
    Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 11:30 +0100
      Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 16:31 +0200
        Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 16:45 +0100
          Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 18:30 +0200
            Re: on the order of the const-keyword Manfred <noname@add.invalid> - 2021-10-30 00:32 +0200
              Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 20:03 -0300
              Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-30 01:10 +0100
            Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 23:51 +0100
    Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 12:22 -0300
      Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 18:34 +0200
        Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 17:04 -0300

csiph-web