Indenting #defines

后端 未结 9 2097
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 00:34

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 #define

9条回答
  •  误落风尘
    2020-11-30 00:37

    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.

    A common solution is to comment the directives, so that you easily know what they refer to:

    #ifdef FOO
    /* a lot of code */
    #endif /* FOO */
    
    #ifndef FOO
    /* a lot of code */
    #endif /* not FOO */
    

提交回复
热议问题