Topic: Pointer declarators
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/10/30 Raw View
James.Kanze@dresdner-bank.com wrote:
[...]
> In the second example, it is the *pointer* which is mutable, not the
> char. You can even legally (and reasonably) write:
>
> mutable char const* p ; // mutable pointer to constant char
>
> All of the possible orderings of mutable, char and const are legal, of
> course.
>
> All of which only proves that the whole thing is a mess, and that it
> really is only a point of personal preference.
Well, not completely. I guess code like
long mutable unsigned const int * p;
will be rejected by about everyone ;-)
Well, there are still 143 other ways to declare p ;-)
---
[ 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 ]
Author: David R Tribble <david@tribble.com>
Date: 1999/10/30 Raw View
"Claude Qu=E9zel" wrote:
>=20
> David R Tribble wrote:
>=20
> > That's obviously a matter of opinion. I prefer 'const' in front
> > of the type. I prefer the way it sounds when pronounced out loud,
> > although it typically sounds fine either way.
> >
> > const int size =3D 1; // const[ant] int[eger]
> > int const big =3D 2; // int[eger] const[ant]
> >
> > const char * p1; // const[ant] char[acter] pointer, or
> > // pointer to const[ant] char[acter]
> > char const * p2; // char[acter] const[ant] pointer, or
> > // pointer to char[acter] const[ant]
> >
> > char *const q1 =3D &c; // char[acter] pointer const[ant], or
> > // pointer const[ant] to char[acter]
> >
> >
> > But again, this is merely my opinion of style.
> >
>=20
> How do you pronouce these :)
>=20
> char const** ptr =3D ...
> const char** ptr =3D ...
Lest I get sucked into another pointless, but amusing, argument...
Yeah, you could pronounce it "character constant pointer [to] pointer",
but when it gets this thorny, go the simplest route:
"... char ... star star" (however you pronounce "char"; I usually
pronounce it "care"). ;-)
-- David R. Tribble, david@tribble.com, http://www.david.tribble.com --
---
[ 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 ]
Author: "Claude Qu zel" <Claude_Quezel@Syntell.corba>
Date: 1999/10/28 Raw View
David R Tribble wrote:
> That's obviously a matter of opinion. I prefer 'const' in front
> of the type. I prefer the way it sounds when pronounced out loud,
> although it typically sounds fine either way.
>
> const int size =3D 1; // const[ant] int[eger]
> int const big =3D 2; // int[eger] const[ant]
>
> const char * p1; // const[ant] char[acter] pointer, or
> // pointer to const[ant] char[acter]
> char const * p2; // char[acter] const[ant] pointer, or
> // pointer to char[acter] const[ant]
>
> char *const q1 =3D &c; // char[acter] pointer const[ant], or
> // pointer const[ant] to char[acter]
>
>
> But again, this is merely my opinion of style.
>
How do you pronouce these :)
char const** ptr =3D ...
const char** ptr =3D ...
--
Claude Qu=E9zel (claude_quezel@syntell.corba)
anti-spam: replace corba by com in private replies
---
[ 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 ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: 1999/10/28 Raw View
On 27 Oct 99 08:41:46 GMT, David R Tribble <david@tribble.com> wrote:
: It's not such a big deal either way in C, but in C++ there is a
: keyword meaning "opposite of const", i.e., mutable. And while I've
: seen lots of folks write 'int const', I've never seen anyone write
: 'int mutable'. So I will, at least in C++, stick with putting the
: cv-qualifier in front of the type.
Guilty of the same misconception. Just the other day I did what you
have never seen.
struct S {
int* mutable i; // mutable.cpp:2: parse error before `mutable'
int mutable* j; // ok, but I wonder
mutable int* k; // ok
};
But hey, I want a mutable pointer to int not a pointer to mutable
int or pointer to int which is mutable.
The other followups seem to indicate that the compiler is wrong,
but they may just not have thought of this case.
I will continue to put my cv qualifiers on the right, but will put
my storage class specifiers on the left. I guess
int* static p;
does look a bit strange.
Smile,
John
---
[ 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 ]
Author: James.Kanze@dresdner-bank.com
Date: 1999/10/28 Raw View
In article <3815D498.549423AE@tribble.com>,
David R Tribble <david@tribble.com> wrote:
> Stephen Baynes wrote:
> > If you write the const after the type (which the standard allows
with
> > the same meaning) then things look much clearer:
> > int_ptr const ptr;
> > int *const same_type_ptr;
> >
> > [My own view is that allowing the const before the type is an
> > abberation in the language definition. Someone at some time must
have
> > thought that const was something like static. Continuing to allow it
> > in the same place perpetuates this confusion as demonstrated in the
> > earlier posting.]
> That's obviously a matter of opinion. I prefer 'const' in front
> of the type. I prefer the way it sounds when pronounced out loud,
> although it typically sounds fine either way.
>
> const int size = 1; // const[ant] int[eger]
> int const big = 2; // int[eger] const[ant]
>
> const char * p1; // const[ant] char[acter] pointer, or
> // pointer to const[ant] char[acter]
> char const * p2; // char[acter] const[ant] pointer, or
> // pointer to char[acter] const[ant]
>
> char *const q1 = &c; // char[acter] pointer const[ant], or
> // pointer const[ant] to char[acter]
> It's not such a big deal either way in C, but in C++ there is a
> keyword meaning "opposite of const", i.e., mutable. And while I've
> seen lots of folks write 'int const', I've never seen anyone write
> 'int mutable'. So I will, at least in C++, stick with putting the
> cv-qualifier in front of the type.
Interesting point, but mutable isn't exactly the opposite of const. The
main argument I present for putting const after the type is consistency:
in many cases (*, ()), you have to, so be consistent. This argument
doesn't apply to mutable. The main argument for the placement of
mutable is that it *is* in some ways like static, and that it must in
some cases be placed in front of what it modifies, so be consistent.
Thus:
const char* p1 ; // pointer to constant char.
mutable char* p2 ; // non-const pointer to char.
In the second example, it is the *pointer* which is mutable, not the
char. You can even legally (and reasonably) write:
mutable char const* p ; // mutable pointer to constant char
All of the possible orderings of mutable, char and const are legal, of
course.
All of which only proves that the whole thing is a mess, and that it
really is only a point of personal preference.
--
James Kanze mailto:James.Kanze@dresdner-bank.com
Conseils en informatique orient e objet/
Beratung in objekt orientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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 ]
Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/10/27 Raw View
David R Tribble wrote:
> [discussion of the relative merits of 'const int' and 'int const']
>
> It's not such a big deal either way in C, but in C++ there is a
> keyword meaning "opposite of const", i.e., mutable. And while I've
> seen lots of folks write 'int const', I've never seen anyone write
> 'int mutable'. So I will, at least in C++, stick with putting the
> cv-qualifier in front of the type.
It's misleading to think of mutable as an anti-const cv-qualifier, because it
isn't. It's a storage class specifier (and one that can only be used for data
members).
As you point out for const, since storage class specifiers and type specifiers
can be put in any order all of these mean the same thing:
const int i;
int const i;
mutable int i;
int mutable i;
Putting storage class specifiers other than first was deprecated in ANSI C89
(6.9.3). Does C99 require storage class specifiers to be first?
---
[ 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 ]
Author: comeau@panix.com (Greg Comeau)
Date: 1999/10/27 Raw View
In article <3815D498.549423AE@tribble.com> David R Tribble <david@tribble.com> writes:
>It's not such a big deal either way in C, but in C++ there is a
>keyword meaning "opposite of const", i.e., mutable. And while I've
>seen lots of folks write 'int const', I've never seen anyone write
>'int mutable'. So I will, at least in C++, stick with putting the
>cv-qualifier in front of the type.
>
>But again, this is merely my opinion of style.
I'll not offer my opinion the issue of where const goes,
but wanted to say that mutable is not exactly the opposite
of const syntactically, and surely in not a cv-qualifier,
but a storage-class. Unfortunately (in C too) storage-classes
are not positional in that they don't need to appear in the beginning
of a decl :(
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C/C++ 4.2.38 -- NOTE 4.2.42 BETAS NOW AVAILABLE
Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
*** WEB: http://www.comeaucomputing.com ***
---
[ 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 ]
Author: David R Tribble <david@tribble.com>
Date: 1999/10/27 Raw View
Stephen Baynes wrote:
> If you write the const after the type (which the standard allows with
> the same meaning) then things look much clearer:
> int_ptr const ptr;
> int *const same_type_ptr;
>
> [My own view is that allowing the const before the type is an
> abberation in the language definition. Someone at some time must have
> thought that const was something like static. Continuing to allow it
> in the same place perpetuates this confusion as demonstrated in the
> earlier posting.]
That's obviously a matter of opinion. I prefer 'const' in front
of the type. I prefer the way it sounds when pronounced out loud,
although it typically sounds fine either way.
const int size = 1; // const[ant] int[eger]
int const big = 2; // int[eger] const[ant]
const char * p1; // const[ant] char[acter] pointer, or
// pointer to const[ant] char[acter]
char const * p2; // char[acter] const[ant] pointer, or
// pointer to char[acter] const[ant]
char *const q1 = &c; // char[acter] pointer const[ant], or
// pointer const[ant] to char[acter]
It's not such a big deal either way in C, but in C++ there is a
keyword meaning "opposite of const", i.e., mutable. And while I've
seen lots of folks write 'int const', I've never seen anyone write
'int mutable'. So I will, at least in C++, stick with putting the
cv-qualifier in front of the type.
But again, this is merely my opinion of style.
-- David R. Tribble, david@tribble.com, http://www.david.tribble.com --
---
[ 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 ]