I suspect I'm Wrong in this, but I always read the former as "char-pointer called fred" and the latter as "char from dereferencing the pointer fred", and as the data type here is the pointer, I go with a).
The semantics are identical. The 'char* fred' version breaks horribly when you try to express anything more complicated a single, simple, declarator within a given declaration (and also implies ignorance of the logic behind C's declarator syntax).
Call me a heathen, but I don't like the syntax that C uses for pointers.
char* foo, bar, baz;, being equivalent to char *foo, bar, baz; defines one pointer and two static chars. I would prefer it to define all of the same kind - and if that were the case then I'd go for the first option. I chose the second due to the way C works.
char* foo, bar is the strongest reason to the latter typing method; however heathen that I am I stick to the first one in order to indicate the type and when using char I don't use multiple declarations to be safe.
The logic behind it is that declaration matches use. Arguably declarator syntax could be improved by making the dereferencing operator (for both declararation and use) postfix, so you never needed to worry about precedence in declarators. It'd have to be different from *, of course, but that needn't be a problem. @ might be a reasonable choice.
I say "char *fred" is correct and "char* fred" is wrong; it's not merely a matter of personal preference.
We have an extremely liberal attitude to coding style in our office, but that's still one of the things on which we're unanimous and emphatic. To write "char* fred" is to misunderstand C/C++. You wouldn't write "x =- y", would you?
And the first style is complete doom once you start writing code containing pointers to functions, const, arrays, multiple layers of pointers, etc.
no subject
But then, I'm a Java programmer these days ;)
no subject
no subject
char *a, b, *c;
business but never got as far as writing anything like that myself anyway. I just work on my own (flawed) parsing of 'char[ ]*' into english.
no subject
no subject
char* foo, bar, baz;, being equivalent to char *foo, bar, baz; defines one pointer and two static chars. I would prefer it to define all of the same kind - and if that were the case then I'd go for the first option. I chose the second due to the way C works.
no subject
no subject
no subject
no subject
Indeed; C pointer syntax is not sensible.
no subject
no subject
no subject
no subject
Excellent icon by the way :)
no subject
We have an extremely liberal attitude to coding style in our office, but that's still one of the things on which we're unanimous and emphatic. To write "char* fred" is to misunderstand C/C++. You wouldn't write "x =- y", would you?
And the first style is complete doom once you start writing code containing pointers to functions, const, arrays, multiple layers of pointers, etc.
no subject
That said, I do need to overhaul my understanding of the declaration process for C.