* john smith:
NNTP-Posting-Date: Tue, 12 Apr 2005 18:53:19 MST
Date: Mon, 11 Apr 2005 20:03:55 -0700
Xref: uni-berlin.de comp.lang.c++:859528
Seems to be something wrong with your client software or server.
if I have:
void f( const int* const p )
Do I read this as.
P is a constant pointer to an int whose value is constant?
Yes.
Or, is there another interpretation?
No, but there are a few points to be aware of.
First, placing 'const' at the front is a special case that's allowed
for unfathomable reasons (making the syntax even more complex?); in
the general notation you'd write it as
int const * const p
Second, for a function _definition_ it matters that p is 'const', because
that restricts the usage of p inside the function body. But for a pure
function _declaration_ it does not matter whether p is declared 'const'
or not, because the caller must supply a value anyway, and what happens
to that value from the caller's perspective is the same anyway. And in
fact it's much stronger than "doesn't matter": when the compiler checks
whether two declarations are compatible it first removes top-level 'const'.
However, the 'const' for the 'int' (which is not a top-level 'const') matters
also for the declaration, because that affects what the function can do to the
'int' that the caller supplies a pointer to.
If this sounds confusing, forget it, just remember that there is something.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?