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"?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top