[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [groff] placement of const is _not_ a matter of style ...

From: G. Branden Robinson
Subject: Re: [groff] placement of const is _not_ a matter of style ...
Date: Sat, 5 May 2018 17:30:36 -0400
User-agent: NeoMutt/20170113 (1.7.2)

At 2018-05-05T12:18:26-0400, Mike Bianchi wrote:
> The placement of  const  is _not_ a matter of style!
> >> For example,
> >> in C code, it is very common to see:
> >>
> >>   const char *foo;
> >>
> >> which means something very different from:
> >>
> >>   char const *foo;
> >
> > Actually, it doesn't.  Try it.
> Actually it does.

I have to disagree--find the bug in my example program, then!
(Attached, again.)

>       char *foo const;
> Also means something!

Are you sure?  It appears to be invalid as both C and C++.

$ cat
int main(int argc, char *argv[]) {
    char * c const = 'a';

$ gcc -ggdb -Wall -Werror -O0 -x c ./
./ In function ‘main’:
./ error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before 
     char * c const = 'a';
./ error: expected identifier or ‘(’ before ‘=’ token
     char * c const = 'a';

$ gcc -ggdb -Wall -Werror             -O0  ./
./ In function ‘int main(int, char**)’:
./ error: expected initializer before ‘const’
     char * c const = 'a';

> See

This appears to support what Ralph and I have been saying.

> To my mind this confusion points to a weakness of C and C++.
> It would be much less of an issue if I could ask a compiler.

Strongly agreed.

>       What is the type of  foo ?
> to be certain excacty what I was dealing with when referencing  foo .
> ((Or is there something out there I am not aware of?))
> ((Where is Dennis Ritchie when you need him?  RIP))

K&R somewhat famously abandoned C to its standards committee after ISO C
90.  One could argue that in doing so, they showed greater wisdom than

I read Scott Meyers's _Effective Modern C++_ with interest--and other
emotions which made the following postscript thoroughly unsurprising:


Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]