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

Pages: 1-

Pointer declaration syntax

Name: Anonymous 2006-03-06 10:27

void* ptr;
void *ptr;
void * ptr;

Since every compiler accepts every one of them, which one do you think is the most correct?
I go with void* ptr.

Name: Anonymous 2006-03-06 10:52

void *ptr

Name: Anonymous 2006-03-06 11:05

not quite, we're not talking about the * as the de-reference operator as we would in, for exemple *ptr = &variable;
in this case the * serves simply to mark the declaration as a pointer to a instead of a data type. makes more sense to me to put it right next to the data type.

Name: Anonymous 2006-03-06 11:14

I use
void * ptr;
ptr = *ptr;
because I like whitespace.

Name: Anonymous 2006-03-06 11:45

I prefer void* ptr because I think "the variable is called ptr and it is of type void*"

Name: Anonymous 2006-03-06 13:20

>>3
There is no such thing as "simply to mark" in an algebra. * is an operator that changed the variable declaration following it into a pointer declaration.

For those who like to put the star next to the type, consider what kind of variables this declares:int* foo, bar

Name: Anonymous 2006-03-06 13:44

There is no such thing like "most correct". It's personal preference. If every compiler accepts every one of them than it's ok. Just use what you like.

I prefer:
int *foomostly because of the example provided in >>6

Name: Anonymous 2006-03-06 22:41

void* ptr;

and

void *ptr;

is a religious style war.

void * ptr;

is just silly.

Name: Anonymous 2006-03-06 23:35

Hay guyz lets have another stupid noob discussion.

Name: Anonymous 2006-03-07 1:11

okay
wuts moar 1337 d00d, assembly or php?

Name: Anonymous 2006-03-08 11:10

void*ptr;
is clearly superior.

Name: Anonymous 2010-12-05 23:58

int* a, b; /* oops */
int *a, *b; /* correct */

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