News for hackers. Stuff that matters.
Re:No more confusions on tricky C declarations by gmartres on Saturday June 26, 2010 @06:20PM (#1464394)
I disagree, the following:

  int* foo, bar;
could be interpreted as declaring two pointers, whereas:

  int *foo, bar;
makes it clear that only the first variable is a pointer.
Re:No more confusions on tricky C declarations by godDLL on Saturday June 26, 2010 @06:45PM (#1464438)
I don't think you should be declaring mixed types with one statement. Declare a pointer, then declare the `int` separately -- and the mystery is gone.
Re:No more confusions on tricky C declarations by masklinn on Sunday June 27, 2010 @09:57AM (#1465486)
I believe the point is that, with that syntax, you can't declare multiple same-type pointers on the same line
Re:No more confusions on tricky C declarations by scott_s on Saturday June 26, 2010 @07:56PM (#1464539)
I find that problem goes away if you only declare a single variable per line. Generally, I find people who do

  int* foo;
Started with C++ and people who do

  int *foo;
Started with C. I started with C++.
Re:No more confusions on tricky C declarations by dkersten on Saturday June 26, 2010 @09:15PM (#1464648)
I have made the same observation and as someone who started with C++, I think it makes more sense that

    int* i;
is an int pointer named i.

    int *i;
just looks strange.. an int named pointer i umm?

Besides, declaring only one variable per line seems less cluttered to me, so I never get the

    int* a, b;
confusion.
Re:No more confusions on tricky C declarations by prodigal_erik on Sunday June 27, 2010 @12:20AM (#1464893)
I never put the asterisk next to the type, because I wanted to train myself the way the grammar actually works rather than the way almost everyone wished it worked.
Re:No more confusions on tricky C declarations by scott_s on Sunday June 27, 2010 @08:06AM (#1465383)
But the compiler recognizes the type of the variable as int*.
Re:No more confusions on tricky C declarations by rbonvall on Sunday June 27, 2010 @12:10AM (#1464877)
When used in an expression, I read p as "what's pointed by p". In a declaration, this applies as well:

    int *i;
means "what's pointed by i is an int".
Re:No more confusions on tricky C declarations by dkersten on Sunday June 27, 2010 @10:56AM (#1465538)
That makes more sense alright, but I still think it would make a lot more sense if * was bound to the type.
Re:No more confusions on tricky C declarations by rue on Sunday June 27, 2010 @05:39AM (#1465280)
Declaring two different types on the same line is fraught with confusion, so it is to be avoided.