The differences between if else and #if #else #endif

后端 未结 3 1890
感情败类
感情败类 2021-01-29 15:36

I am confused between the if/else and #if/#else/#endif constructs.

  1. What are the differences betwee
3条回答
  •  没有蜡笔的小新
    2021-01-29 16:17

    Can I ask what's the differences between them?

    #if #else and #endif are instructions to the compiler, to only compile the code between them, if a compilation level condition (like a macro being defined or having a certain value) is satisfied.

    if and else are parts of the compiled algorithm.

    What kind of specific situations for me to choose each of them?

    The pre-compilation conditions are used to disable parts of the code, in situations where they make no sense (like calls to Windows-specific APIs, when compiling under Linux). They are key to developing cross-platform code (for example).

提交回复
热议问题