Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-24 14:36:52


----- Original Message -----
From: "Daryle Walker" <darylew_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, July 24, 2001 2:26 PM
Subject: [boost] Re: Review: Boost Coding Guidelines

> on 7/24/01 12:40 AM, Tim Butler at tim_at_[hidden] wrote:
>
> [SNIP]
> > ------------------------------------------------------------------
> >> 6.7. Place const after the base type it modifies. This simple rule
makes it
> >> easier to write type declarations correctly and will make your
declarations
> >> consistent with compiler-generated type descriptions in error messages.
> >
> > o I disagree with this simply because I suspect the "const before" form
is
> > more familiar to most people. I think most people find the *compiler*
messages
> > confusing and I don't think it is valuable making them spend extra
effort
> > interpreting declarations in the code with an unfamiliar style. In fact
there
> > are a couple instances in this document that appear wrong but require a
> > "double take".
>
> I also disagree with the compiler message reason, especially since my
> compiler does _not_ do it (i.e. it puts the "const" before the type when
> possible).
>
> There is a better reason; putting the qualifier after its base type makes
> the placement consistent with all types. I don't think you realize that
not
> all types support the pre-qualifier form!

Yes, I do, but apparently I don't always write down the best rationale ;-)

> Pointer declarations, that are
> not hidden in a typedef, must use the post-qualifier form. However, all
> pre-qualifier types can be post-qualified, so using post-qualification all
> the time is the most consistent.
>
> const int i;
> A constant integer
> int const i;
> Also a constant integer
> const int * p;
> A regular (i.e. non-const) pointer to a constant integer
> int const * p;
> Also a regular pointer to a constant integer
> int * const p;
> A constant pointer to a regular integer
> const int ** p;
> A regular pointer to a regular pointer to a constant integer
> int const ** p;
> Also a regular pointer to a regular pointer to a constant integer
> int * const * p;
> A regular pointer to a constant pointer to a regular integer
> int ** const p;
> A constant pointer to a regular pointer to a regular integer
> volatile int const * volatile * const * p;
> A regular pointer to a constant pointer to a volatile
> pointer to a constant & volatile integer
>
> > You might rephrase this:
> >
> > Place const before the base type it modifies. Every C++ textbook does
this and
> > so does the C++ standard. :) (please note smiley)
>
> Use the reason I just gave instead.

Not sure who/what you're responding to here.

Anyway, I doubt this particular point will ever be agreed upon, except if we
say that any form is permissible. I find the pre-qualifier form more
readable myself, but as you say it's less consistent. I'm still trying to
wean myself from it.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk