c - 缩进#define

标签 c c-preprocessor indentation code-formatting

我知道 #define 等通常从不缩进。为什么?

我目前正在编写一些代码,其中混合了#define#ifdef#else s、#endifs 等。所有这些通常与普通 C 代码混合在一起。 #define 的非缩进使得它们难以阅读。缩进代码与非缩进 #define 的混合是一场噩梦。

为什么 #define 通常不缩进?有没有人不缩进的原因(例如下面的这段代码)?

#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

最佳答案

ANSI C 之前的预处理器不允许行首和“#”字符之间有空格;前导“#”必须始终放在第一列。

如今,ANSI C 之前的编译器已经不存在了。使用您喜欢的任何样式(“#”前的空格或“#”与标识符之间的空格)。

http://www.delorie.com/gnu/docs/gcc/cpp_48.html

关于c - 缩进#define,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/789073/

相关文章:

c++ - 在这里进行位移有什么意义?

c - 使用 strcat 的段错误

c - 是否有一种干净的可移植方式来处理 "build"包含文件名

python - Python 的原子编辑器缩进错误

javascript - 逐行缩进Javascript文件?

c - 当 POSIX 说 stderr 应该可以读写时是什么意思?

c - 如何在C中将两个整数的和存储到一个long变量中?

c++ - 如何在预处理阶段获取 C++ 函数调用者名称

c++ - 如何在 C++ 宏中转换标识符字母大小写

javascript - JS 创建一个方法来缩进文本