robinbloke: (Default)
[personal profile] robinbloke
[Poll #777592]

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

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

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

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

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

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

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

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

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

Indeed; C pointer syntax is not sensible.

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

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

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

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

Excellent icon by the way :)

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

Date: 2006-07-25 10:31 am (UTC)
From: [identity profile] robinbloke.livejournal.com
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.

Profile

robinbloke: (Default)
robinbloke

January 2016

S M T W T F S
     12
3456789
10111213141516
17181920212223
24 252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 1st, 2025 11:34 pm
Powered by Dreamwidth Studios