On Sat, Sep 29, 2012 at 01:24:49PM -0400, Joe Wronski wrote: > In fact, how would the compiler interpret these two statements? >=20 > int *a, b; > int * c, d; >=20 > I'm pretty sure a is a pointer to int, b is an int, c is a pointer, but=20 > not quite sure about d. It's an int. This is the reason why the '*' is associated with the variable, not the type. Semeantically I've always treated int *c as ' *c is an int, so c has the address of an int' BAJ >=20 > How about a struct typedef ? >=20 > typedef struct tag_fooT { > int foo; > char *s; > } fooT, *pfooT; >=20 > I know that declaring a fooT allocates space for the structure, and=20 > declaring a pfooT allocates just the pointer as I do this all the time. Correct. BAJ >=20 > fooT fooStructA; > pfooT fooPointer =3D &fooStructA; >=20 >=20 > Joe W >=20 >=20 > On 9/29/2012 12:49 PM, Tamas Rudnai wrote: > > I prefer B, that is the most common -- plus as you have pointed out, wi= th > > the 'int' you only told the compiler the base type, but with the '*' yo= u > > are telling that this particular variable is a pointer type to that bas= e > > type. So even if syntax allows you to do the way A, semantically it is > > still the way B. > > > > Tamas > > > > > > On 29 September 2012 09:17, V G wrote: > > > >> This is an opinion question. I am curious as to what you all think is = a > >> good way to do this: > >> > >> In C/C++, what is your preferred way or declaring pointers? > >> > >> A) int* p; > >> B) int *p; > >> C) int * p; > >> > >> I think it should be A because it's logical and the C/C++ compiler > >> considersint*to be the type, and the syntax is ; > >> > >> However, I see B a lot in code, and it doesn't make sense to me. Also, > >> function prototypes are usually written like so: > >> > >> void myFunction(int*, int*, char*); with the asterisk close to the typ= e. > >> > >> Note that when doing this: > >> > >> int* x, y; > >> > >> Type type of x is int* whereas the type of y is int. To make the type = of > >> both of them int*, one must do: > >> > >> int *x, *y; > >> > >> Apparently, the spaces get removed during compile time and it just bec= omes > >> int*x to the compiler. > >> * > >> Which way do you prefer?* > >> -- > >> http://www.piclist.com PIC/SX FAQ & list archive > >> View/change your membership options at > >> http://mailman.mit.edu/mailman/listinfo/piclist > >> > > > > > > >=20 > --=20 > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 Byron A. Jeff Chair: Department of Computer Science and Information Technology College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .