1

我发现了一个 C 程序,作者在类型声明中在变量名之前添加了一个空格:

int * foo;

GNU 缩进总是删除这个空格,不管是什么风格(GNU、K&R、Linux)。我发现在任何地方都没有明确提到这个约定。除了“没人做”之外,我能告诉这个程序的作者什么?

4

2 回答 2

4

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.

于 2013-10-04T17:56:33.203 回答
2

K&R 风格表明它应该是

int *foo;  

除了“没人做”之外,我能告诉这个程序的作者什么?

什么都不告诉他。这是一个选择问题。
并阅读这个美丽的答案

于 2013-10-04T17:41:30.297 回答