Rainer Weikusat said:
Keith Thompson said:
Rainer Weikusat said:
4. Does anyone care where the pointer * is? I prefer keeping to next
to the type, rather than next to the variable name.
EG. I like: char* firstName; and not so much: char *firstName;
C knows about three kinds of derived types, arrays
char a[];
Pointers to functions
char (*a)();
and pointers
char *a;
Array types, structure types, union types, function types, and pointer
types are all derived types (C99 6.2.5).
Exercise for the reader: Which of the six types defined above are
irrelevant for this statement about 'declaration of derived types'
because they belong to a different syntactical class than the three
examples? Which type is irrelevant because it cannot directly appear
in a variable declaration? Which other class of types should appear
instead because they can?
You said that "C knows about three kinds of derived types". In fact,
there are six. I was disputing the accuracy of your statement, not
its relevance.
A type 'char*' doesn't exist. A type named 'char' does, and assuming
that T names an existing type, an object can be declared as 'pointer
to a T' by using the syntax
T *o;
'Pointerness' is an attribute of the object, not of the type. This is
also consistent with the original intention behind this syntax, namely
that 'declaration should resemble use'.
Wrong. char* is a type. Specifically, it's a derived type and a
pointer type. See C99 6.2.5, particularly paragraph 20.
If char* is not a type, can you explain what exactly you mean when you
use the word "type"? Your usage appears to be inconsistent with the
usage in the C standard.
You might have a valid point in there somewhere, but your misuse of
terminology makes it difficult to discuss it.
(And for the record, I agree that "T *o;" is preferable to
"T* o;"; I just don't agree that it's a huge deal.)
[...]
Why not? Or are you just being rude?
They are bound to end up as quite useless quarrels between people
who desire to write "beautiful" code and people who desire to write
readable code.
Perhaps, but we've also seen some useful discussion in this thread,
particularly the point about the importance of conforming to whatever
coding standard is used for an existing project.