News for hackers. Stuff that matters.
Re:No more confusions on tricky C declarations by ewjordan on Sunday June 27, 2010 @12:01AM (#1464865)
Sorry, that didn't make much sense to me - in your first example, you can't say "foo is an int", because it's not, it's a pointer to an int. And in your last example, you can't say "foo[5] is an int", because it's not, it's a pointer to int.

In response to the original question, I think the answer is that

  int *foo;
is a common way of writing it because that's the way the compiler resolves it. As mentioned elsewhere,

  int* foo, bar;
is equivalent to

  int *foo; int bar
so treating the star as part of the type can cause problems.

But I agree fully - it makes a lot more sense to me to consider the pointer star as a flag on the type, not a modifier to the name. Just one of the many warts on C and C++ that make me happy I have to use them so infrequently...

[Edit: formatting, stars were getting swallowed when put inline]

Re:No more confusions on tricky C declarations by lmkg on Sunday June 27, 2010 @06:00PM (#1466336)
> [Edit: formatting, stars were getting swallowed when put inline]

The same thing happened to the post you're responding to, and that's why it's not making sense to you. The author really meant to say star-foo and star-foo[5], but instead italicized a bunch of text in between.

Re:No more confusions on tricky C declarations by ewjordan on Monday June 28, 2010 @01:18PM (#1468597)
D'oh.

Don't know how I didn't realize that, given that my response got messed up so that my "corrected" version read exactly like the one I was confused about...

Please disregard everything I said, in that case. :)