How do you use #define?

前端 未结 8 853
鱼传尺愫
鱼传尺愫 2020-12-11 15:03

I\'m wondering about instances when it makes sent to use #define and #if statements. I\'ve known about it for a while, but never incorporated it into my way of coding. How e

8条回答
  •  攒了一身酷
    2020-12-11 15:31

    Well, defines are used often for compile time constants and macros. This can make your code a bit faster as there are really no function calls, the output values of the macros are determined at compile time. The #if's are very useful. The most simple example that I can think of is checking for a debug build to add in some extra logging or messaging, maybe even some debugging functions. You can also check different environment variables this way.

    Others with more C/C++ experience can add more I am sure.

提交回复
热议问题