Question

I discovered a C program where the author adds a whitespace in type declarations, before the variable name:

int * foo;

GNU indent always deletes this whitespace, whatever the style (GNU, K&R, Linux). I find no explicit mention of this convention anywhere. What can I tell the author of this program, except "nobody does it"?

Was it helpful?

Solution

There's justification for the style T *p; - that's how the grammar works.
There's justification for the style T* p; - it emphasizes that p has pointer type.

There's no real justification for T * p; other than it may look pretty to someone. Having said that, style is only an issue if it leads to confusion. If he's just declaring the one variable per line, then I don't think this is a problem. If he's writing something like

int * foo, bar;

then you might want to politely suggest he use the convention

int *foo, bar;

to make it clear that only foo is being declared as a pointer.

OTHER TIPS

K&R style states that it should be

int *foo;  

What can I tell the author of this program, except "nobody does it"?

Tell him nothing. It is a matter of choice.
And read this beautiful answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top