Reputation: 16086
I wonder if there is a way to set the value of #define in run time.
I assume that there is a query for Oracle specific and Sql Server specific at the code below.
#define oracle
// ...
#if oracle
// some code
#else
// some different code.
#endif
Upvotes: 4
Views: 7771
Reputation: 255
To be complete: These optimization slides for OpenCL imply at page 11 that it is possible, but note that the author seems to interpret "runtime" as the hull program's runtime. In this sense, the kernels (small programs for each GPU thread) are "compiled at runtime".
Upvotes: 0
Reputation: 43452
No, the preprocessor runs before compile and can alter code at that time, that is its purpose, if you want to switch behavior based on something at runtime use a variable and normal conditional logic.
Upvotes: 0
Reputation: 1062780
#if
is compile-time. You could specify this in your build process (via switches to msbuild/csc), but not really at runtime. The excluded code doesn't exist. You might be better advised to (1 of):
Upvotes: 2
Reputation: 74654
Absolutely not, #defines are compiled out by the preprocessor before the compiler even sees it - so the token 'oracle' isn't even in your code, just '1' or '0'. Change the #define to a global variable or (better) a function that returns the correct value.
Upvotes: 15