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.) > AND > char *foo const; > Also means something! Are you sure? It appears to be invalid as both C and C++. $ cat const.cc int main(int argc, char *argv[]) { char * c const = 'a'; } $ gcc -ggdb -Wall -Werror -O0 -x c ./const.cc ./const.cc: In function ‘main’: ./const.cc:2:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’ char * c const = 'a'; ^~~~~ ./const.cc:2:20: error: expected identifier or ‘(’ before ‘=’ token char * c const = 'a'; ^ $ gcc -ggdb -Wall -Werror -O0 ./const.cc ./const.cc: In function ‘int main(int, char**)’: ./const.cc:2:14: error: expected initializer before ‘const’ char * c const = 'a'; ^~~~~ > See > > https://stackoverflow.com/questions/890535/what-is-the-difference-between-char-const-and-const-char 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 Bjarne. I read Scott Meyers's _Effective Modern C++_ with interest--and other emotions which made the following postscript thoroughly unsurprising: https://scottmeyers.blogspot.fr/2015/12/good-to-go.html -- Regards, Branden
signature.asc
Description: PGP signature