#定义缩进 [英] Indenting #defines

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

问题描述

我知道的#define S等通常是从来没有缩进。为什么呢?

我在里面有的#define S, #IFDEF 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 #defines, etc. are normally never indented. Why?

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.

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 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屋!

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