c-preprocessor

Allow use of member variable depending on preprocessor directives

无人久伴 提交于 2020-08-26 10:07:13
问题 Consider the following class: class Foo { public: #ifdef CONDITION int x = 0; #endif int y; int foo() { #ifdef CONDITION return ++x; #else return 0; #endif } } int x only exists when I define CONDITION - either through a #define CONDITION or as a preprocessor definition ( -D CONDITION ) This has the neat advantage that I can't compile it I use x by mistake somewhere when CONDITION isn't defined. For example: If, by mistake, I write something like: Foo f; f.x = 10; This will not be allowed to

Digraph and trigraph can't work together?

拜拜、爱过 提交于 2020-08-25 07:05:02
问题 I'm learning digraph and trigraph, and here is the code which I cannot understand. (Yes, I admit that it's extremely ugly.) This code can compile: #define _(s) s%:%:s main(_(_)) <% __; %>t This code can compile, too: #define _(s) s??=??=s main(_(_)) <% __; %> However, neither of the following two pieces of code can compile: #define _(s) s%:??=s main(_(_)) <% __; %> And #define _(s) s??=%:s main(_(_)) <% __; %> This does confuse me: Since the first two pieces of code can compile, I suppose the

Are the #if DEBUG statements really needed for previews in SwiftUI to remove it in a release build?

我怕爱的太早我们不能终老 提交于 2020-08-22 08:28:28
问题 The preprocessor macro's are pretty commonly seen in the SwiftUI official tutorials/videos, e.g.: #if DEBUG struct ContentView_Previews : PreviewProvider { static var previews: some View { ContentView() } } #endif Are those needed? The compiler can surely see that the struct isn't used internally and omit the whole struct since the access modifier is implicit internal right? I think that everything that conforms to PreviewProvider can be removed away, but maybe that isn't the case for every