Re:C/C++ Pointer Declaration Syntax – It makes sense
by scott_s on Tuesday February 21, 2012 @09:35AM
(#3616555)
I learned C++ before learning C, so I tend to use the C++ convention of
The reasoning in K&R (also presented in the article) has always bothered me. When the compiler builds a symbol table, it has "ident" as the identifier, and "type*" as its type. When the compiler emits type related error messages, it uses that identifier and type to communicate with you.
[ Parent
| on HN ]
Re:C/C++ Pointer Declaration Syntax – It makes sense
by slowpoke on Tuesday February 21, 2012 @09:57AM
(#3616636)
My thoughts exactly. Actually, I'd go as far as to say that using the same character for both the type declaration of pointers and the operator for dereferencing pointers was a mistake in the first place.
Imagine they'd have used this instead, for example:
int. a; // declares a pointer to an int named a
*a = 42; // dereference the pointer
Yea, looks weird on first sight (because we're used to current style), but the difference is glaringly obvious: it's visually apparent that the two do completely different things. It doesn't need to be the dot, by the way. My point is that any symbol that's different would have been better than using the same one.