From 8820454624277435239
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fe6310a7fb6a4c8c
X-Google-Attributes: gidf78e5,public
From: David R Tribble <dtribble@flash.net>
Subject: Re: const int& or int const&
Date: 1998/02/09
Message-ID: <34DE9758.4DAB@flash.net>#1/1
X-Deja-AN: 323481574
Content-Transfer-Encoding: 7bit
References: <34D8AD3C.5C38416B@heidelbg.ibm.com> <34D9D6B5.30EE@central.beasys.com> <34DBE467.521EA970@vizdom.com>
Mime-Version: 1.0
Originator: clamage@taumet
X-NNTP-Posting-Host: dasc27-83.flash.net
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
Organization: Flashnet Communications, http://www.flash.net
Newsgroups: comp.std.c++


I, David R Tribble wrote:
> > There seems to be a minority of programmers who insist on
> > placing the 'const' specifier of a type after the type, such
> > as 'int const' instead of 'const int'.  Personally I abhor this
> > style; it's just another way to confuse people and is a break from
> > well-accepted practice that's been around for several years now.

John Lacey wrote:
> The entire declaration syntax is regrettable and confusing.
> 
> The reason for the behavior of the minority, as I'm sure David
> knows, is that "const" is a postfix qualifier, except when it
> appears in the left-most position.

I can buy that.  But tradition is tradition, and we must also consider
what we teach beginning programmers.  I've always felt that too
many ways to state the same thing was a bad idea; you need to learn
two or more syntaxes for the same thing, but what have you gained
with this extra knowledge?   In many situations, two ways is one too
many.

> Two questions come to mind. Is there a good reason why "const" is
> postfix rather than prefix?

There had to be a way to specify constant pointers without breaking
the existing syntax for pointers to constant objects.  Hence, we have
'type *const' and 'const type *', respectively (and 'const type *const'
for cases of both).

> Also, does volatile behave the same
> way, or does it behave like a storage-class specifier, despite
> being listed in the grammar, along with const, as a
> type-qualifier?

'volatile' is syntactically identical to 'const'.  (In C9X, the new
qualifier 'restrict' acts this way, too.)  They share common ground
semantically, so it makes sense that they should be syntactically
similar.  But 'mutable' is a storage-class specifier like 'static'
[7.1.1], even though it arguably shares some semantics with 'const'.
Strange, no?

______________________________________________________________________
David R. Tribble
dtribble@technologist.com
dtribble@flash.net              http://www.flash.net/~dtribble/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




