robinbloke: (Default)
robinbloke ([personal profile] robinbloke) wrote2006-07-25 10:12 am
Entry tags:

[identity profile] duncanneko.livejournal.com 2006-07-25 09:17 am (UTC)(link)
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).

But then, I'm a Java programmer these days ;)
ext_8103: (Default)

[identity profile] ewx.livejournal.com 2006-07-25 09:27 am (UTC)(link)
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).

[identity profile] duncanneko.livejournal.com 2006-07-25 09:38 am (UTC)(link)
Well, I was right about being Wrong ;) I was vaguely aware of the

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.

[identity profile] robinbloke.livejournal.com 2006-07-25 09:49 am (UTC)(link)
Java? Bah, get yourself a real language bucko ;)

[identity profile] mattp.livejournal.com 2006-07-25 09:18 am (UTC)(link)
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.

[identity profile] robinbloke.livejournal.com 2006-07-25 09:51 am (UTC)(link)
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.

[identity profile] deliberateblank.livejournal.com 2006-07-25 05:30 pm (UTC)(link)
Of course when you're using int it's perfectly safe...

[identity profile] robinbloke.livejournal.com 2006-07-25 05:56 pm (UTC)(link)
Doesn't everyone know that?

[identity profile] sunflowerinrain.livejournal.com 2006-07-25 04:25 pm (UTC)(link)
I chose the second due to the way C works

Indeed; C pointer syntax is not sensible.
ext_8103: (Default)

[identity profile] ewx.livejournal.com 2006-07-31 01:44 pm (UTC)(link)
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.

[identity profile] robinbloke.livejournal.com 2006-07-31 02:16 pm (UTC)(link)
I still need to read up on this...

[identity profile] silja.livejournal.com 2006-07-25 09:51 am (UTC)(link)
aack you missed the aack clicky box sniffle aack

[identity profile] robinbloke.livejournal.com 2006-07-25 09:53 am (UTC)(link)
Apologies; I shall double the ack content for my next poll - if I remember;

Excellent icon by the way :)
gerald_duck: (ascii)

[personal profile] gerald_duck 2006-07-25 10:11 am (UTC)(link)
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.

[identity profile] robinbloke.livejournal.com 2006-07-25 10:31 am (UTC)(link)
I work so rarely with multiple levels of pointers or const pointers (etc) that this hasn't been an issue for me.

That said, I do need to overhaul my understanding of the declaration process for C.