#定义缩进 [英] Indenting #defines
问题描述
我知道的#define
S等通常是从来没有缩进。为什么呢?
我在里面有的#define
S, #IFDEF $的一个可怕的混合当下一些code工作C $ C> S,
的#else
S, #ENDIF
S,等等。所有这些经常混在普通的C code。在的#define
S的非缩进,使他们难以阅读。和缩进code与非缩进的#define
S中的混合物是一场噩梦。
什么是不能缩进的#define
S的好处?这是否让我一个坏人,如果我缩进呢?这不是好多了?
#IFDEF SDCC
#如果调试== 1
#如果定义(pic18f2480)
#定义FLASH_MEMORY_END 0x3DC0
#elif指令定义(pic18f2580)
#定义FLASH_MEMORY_END 0x7DC0
#其他
#ERROR无法设置闪存结束了!
#万一
#其他
#如果定义(pic18f2480)
#定义FLASH_MEMORY_END 0x4000的
#elif指令定义(pic18f2580)
#定义FLASH_MEMORY_END为0x8000
#其他
#ERROR无法设置闪存结束了!
#万一
#万一
#其他
#如果调试== 1
#定义FLASH_MEMORY_END 0x7DC0
#其他
#定义FLASH_MEMORY_END为0x8000
#万一
#万一
pre-ANSI C preprocessor并不允许行和#字符开始之间的空间;领先的#不得不总是被放置在第一列
pre-ANSI C编译器是不存在的这些日子。使用哪种风格永远(空间之前,#或空格#之间以及标识符)你preFER。
<一个href=\"http://www.delorie.com/gnu/docs/gcc/cpp_48.html\">http://www.delorie.com/gnu/docs/gcc/cpp_48.html
I know that #define
s, etc. are normally never indented. Why?
I'm working in some code at the moment which has a horrible mixture of #define
s, #ifdef
s, #else
s, #endif
s, etc. All these often mixed in with normal C code. The non-indenting of the #define
s makes them hard to read. And the mixture of indented code with non-indented #define
s is a nightmare.
What is the benefit of not indenting #define
s? Does it make me a bad person if I indent them? Isn't this much nicer?
#ifdef SDCC
#if DEBUGGING == 1
#if defined (pic18f2480)
#define FLASH_MEMORY_END 0x3DC0
#elif defined (pic18f2580)
#define FLASH_MEMORY_END 0x7DC0
#else
#error "Can't set up flash memory end!"
#endif
#else
#if defined (pic18f2480)
#define FLASH_MEMORY_END 0x4000
#elif defined (pic18f2580)
#define FLASH_MEMORY_END 0x8000
#else
#error "Can't set up flash memory end!"
#endif
#endif
#else
#if DEBUGGING == 1
#define FLASH_MEMORY_END 0x7DC0
#else
#define FLASH_MEMORY_END 0x8000
#endif
#endif
Pre-ANSI C preprocessor did not allow for space between the start of a line and the "#" character; the leading "#" had to always be placed in the first column.
Pre-ANSI C compilers are non-existent these days. Use which ever style (space before "#" or space between "#" and the identifier) you prefer.
http://www.delorie.com/gnu/docs/gcc/cpp_48.html
这篇关于#定义缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!