4 ms·
This bothers me so much about C/C++ syntax. int* a, b; should clearly declare two int pointers, not one int pointer and one int. Stroustrup wrote something
by alecbenzer 15y ago
This bothers me so much about C/C++ syntax.
int* a, b;
should clearly declare two int pointers, not one int pointer and one int.
Stroustrup wrote something somewhere where he explained that
int* a;
is more appropriate for use in C++ because C++ is supposed to be more focused on types, and
int * a;
is more appropriate for C because of something about C's philosophy, but I can't remember what. I wish they would have changed the syntax for C++, but I guess he couldn't have while still keeping C++ a superset of C.
edit: found it: http://www2.research.att.com/~bs/bs_faq2.html#whitespace http://www2.research.att.com/~bs/bs_faq2.html#whitespace
"A ``typical C programmer'' writes ``int p;'' and explains it ``p is what is the int'' emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar.
A ``typical C++ programmer'' writes ``int* p;'' and explains it ``p is a pointer to an int'' emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well."