C代码宏/#定义缩进?

问题描述:

我很好奇,为什么我看到此格式,几乎所有C宏:

I'm curious as to why I see nearly all C macros formatted like this:

#ifndef FOO
#   define FOO
#endif

或者这样:

#ifndef FOO
#define FOO
#endif

但从来没有这样的:

But never this:

#ifndef FOO
    #define FOO
#endif

(而且,Vim的 = 运营商似乎只算前两个是正确的。)

(moreover, vim's = operator only seems to count the first two as correct.)

这是由于可移植性语言编译器之间的问题,还是仅仅是一个标准的做法?

Is this due to portability issues among compilers, or is it just a standard practice?

IIRC,老年çpreprocessors要求#要上线的第一个字符(虽然我从来没有实际遇到一个有这个要求) 。

IIRC, older C preprocessors required the # to be the first character on the line (though I've never actually encountered one that had this requirement).

我从来没有见过你的code喜欢你的第一个例子。我平时写preprocessor指令作为你的第二个例子。我发现,它在视觉上与实际code的压痕较少受干扰(不,我用C写了)。

I never seen your code like your first example. I usually wrote preprocessor directives as in your second example. I found that it visually interfered with the indentation of the actual code less (not that I write in C anymore).

的 GNU C preprocessor手动说:

preprocessing指令是在线路
  你的程序以'#'开始。
  在空白前后允许
  在'#'。

Preprocessing directives are lines in your program that start with '#'. Whitespace is allowed before and after the '#'.