History of 'const' grammar

W

Wolfgang Draxinger

Does anybody know, why a special case for 'const' has been
introduced that it is R-associative, if it is at the beginning
of a declaration / definition, but otherwise L-associative
(which I find easier to read BTW).

In my code one will always find me writing

int const a;

instead of the equivalent

const int a;

The former looks much nicer to me. Also to me it looks a lot less
confusing to write

int const * const foo;

instead of

const int * const foo;


Wolfgang
 
S

Stefan Ram

Wolfgang Draxinger said:
Does anybody know, why a special case for 'const' has been
introduced that it is R-associative, if it is at the beginning
of a declaration / definition, but otherwise L-associative

This rule has only been introduced in your phantasy.
Therefore, you should know best why.

The C grammar merely states:

<declaration>::=<declaration-specifiers>[<init-declarator-list>]";".
<declaration-specifiers>::=<type-qualifier>[<declaration-specifiers>].
In my code one will always find me writing
int const a;
instead of the equivalent
const int a;

see

http://www.dansaks.com/articles/1999-02 const T vs T const.pdf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top