--_002_a7ljj9xapjln2skaterswarbrick_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable V G writes: > 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 type. The mature free software libraries that I have seen generally name arguments to functions in the declarations as well. This serves as a sort of minimal documentation and there's not really any downside to doing so. As a result, I would expect to see void myFunction (int *a, int *b, char *str) (except I wouldn't use camelCase likeThat) > > 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; This is why most experienced C programmers prefer "style B". int *x, y; looks more like the * applies only to the x. > > Apparently, the spaces get removed during compile time and it just become= s > int*x to the compiler. Well, that doesn't really make much sense. White space is always pretty much ignored in C: what is going on is that the "*" binds more tightly than the comma. (Although, strictly speaking, I don't think the comma or the asterisk in such a statement is acting as an operator, so binding precedence isn't quite the right language for it) > * > Which way do you prefer?* The right one, B :-) Rupert --_002_a7ljj9xapjln2skaterswarbrick_ Content-Type: text/plain; name="ATT00001.txt" Content-Description: ATT00001.txt Content-Disposition: attachment; filename="ATT00001.txt"; size=208; creation-date="Sat, 29 Sep 2012 17:07:04 GMT"; modification-date="Sat, 29 Sep 2012 17:07:04 GMT" Content-Transfer-Encoding: base64 LS0gDQpodHRwOi8vd3d3LnBpY2xpc3QuY29tIFBJQy9TWCBGQVEgJiBsaXN0IGFyY2hpdmUNClZp ZXcvY2hhbmdlIHlvdXIgbWVtYmVyc2hpcCBvcHRpb25zIGF0DQpodHRwOi8vbWFpbG1hbi5taXQu ZWR1L21haWxtYW4vbGlzdGluZm8vcGljbGlzdA0K --_002_a7ljj9xapjln2skaterswarbrick_-- .