Re: Const correctness and fun
Re: Const correctness and fun
- Subject: Re: Const correctness and fun
- From: Daryle Walker <email@hidden>
- Date: Mon, 20 Jun 2005 02:41:17 -0400
On Jun 16, 2005, at 1:52 PM, Andreas Grosam <email@hidden>
wrote:
On 13.06.2005, at 19:10, Cameron Hayne wrote:
On 13-Jun-05, at 12:30 PM, David Fang wrote:
I used to be confused about it a long time ago. Someone
summarized in an earlier post: "const" modifies the thing to the
left. If there's nothing to the left, then it applies to the right.
I think it is easier to just always read declarations from right
to left (* is read as "pointer to"):
const char* cs
cs is a pointer to a const char
char* const cs
cs is a const pointer to char
For constant strings, I like
char const * const str1 = "Hello";
since you usually don't want neither the characters to change, NOR
the string's pointer to change. (Most people forget the second
"const," although they'll never reassign the pointer.) Of course,
you drop the pointer gymnastics by saying what you really mean:
char const str2[] = "World";
No confusing about placing "const" around a "*" here. This is the
form I try to use.
I tend to put the "const" after its base type, since pointer types
require it.
well, since we are here ;-)
a riddle, what is this:
typedef char const * (ns::X:: * const MF) (const char * const *)
const;
1. It defines a type-alias named "MF"
2. Objects of this type are always "const"
3. The type describes a member pointer for the type "ns::X"
4. The qualifying members (of "ns::X") that this pointer can be used
for are
A. non-static member functions that don't modify their "this"
object
B. return a "char const *"
C. take a single parameter, of type "const char * const *"
Hope that I'm right....
--
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden