Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

int* p vs. int *p

Name: Anonymous 2009-10-29 0:18

What do you think about the difference between the following declarations? Which do you prefer?

int* p;
int *p;

It's often said the first is C++ style and the second is C style. I prefer C but conceptually the first declaration makes a lot more sense to me. You're defining a variable p of type int*. p is an int*. You dereference it, *p, when you want the int. Makes sense. The second example to me seems like gobbledygook, but it's the way the C authors thought of it, because of this bullshit:

int *p, *q;

So what the fuck is the deal? Can someone who uses "int *p" syntax explain to me what goes through your head when you write that garbage?

Name: Anonymous 2009-10-29 16:12

>>5
http://www.antlr.org/wiki/display/CS652/How+To+Read+C+Declarations

By the way! This is a nice explanation, but shit like this:
int *func_returning_ptr_to_int();
Makes me FUQIN RAGE! You forgot your void, moron! It is C, not C++! You never, ever, ever declare a function with empty arglist, that's just asking for a well-deserved trouble, bitch!

Also, he could have mentioned whence the "look right, then look left" rule comes: it's because the only two operators allowed in declarations are '*' and '[]', and '[]' has higher precedence and goes to the right.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List