#if vs #ifndef vs #ifdef

后端 未结 5 637
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 00:27

My problem is first of all, understanding #ifndef and #ifdef. I also want to understand the difference between #if, #ifndef

5条回答
  •  没有蜡笔的小新
    2021-01-03 01:18

    #if is preprocessor if. It can only deal with with preprocessor stuff which is basically preprocessor macros (which are either function like or constant-like) and C tokens with some simple integer-literal arithmetic.

    #ifdef SOMETHING is the same as #if defined(SOMETHING) and #ifndef SOMETHING is the same as #if !defined(SOMETHING). defined is a special preprocessor operator that allows you to test whether SOMETHING is a defined macro. These are basically shortcuts for the most common uses or preprocessor conditionals -- testing whether some macros are defined or not.

    You can find a detailed manual (~80 pages) on the gcc preprocessor at https://gcc.gnu.org/onlinedocs/ .

提交回复
热议问题