C代码宏/#定义缩进? [英] C macro/#define indentation?

查看:242
本文介绍了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).

的<一个href=\"http://gcc.gnu.org/onlinedocs/cpp/The-$p$pprocessing-language.html#The-$p$pprocessing-language\"相对=nofollow> GNU C preprocessor手动说:

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

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

这篇关于C代码宏/#定义缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆