缩进#defines [英] Indenting #defines

查看:212
本文介绍了缩进#defines的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know that #defines, etc. are normally never indented. Why?

我现在在一些代码工作,有一个可怕的混合 #define #ifdef s, #else s, #endif s ,等等。所有这些通常与正常的C代码混合。 #define 的非缩进使得它们难以阅读。和缩进代码与非缩进 #define 的混合是一个噩梦。

I'm working in some code at the moment which has a horrible mixture of #defines, #ifdefs, #elses, #endifs, etc. All these often mixed in with normal C code. The non-indenting of the #defines makes them hard to read. And the mixture of indented code with non-indented #defines is a nightmare.

不缩进 #define s?如果我缩进它,它会让我一个坏人吗?这不是更好吗?

What is the benefit of not indenting #defines? 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预处理器不允许在行的开始和#字符之间有空格;前导#必须始终放在第一列。

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.

这些天前,ANSI C编译器不存在。

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

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

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