質問

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