preprocessor-directive

Macro compiler error

半城伤御伤魂 提交于 2019-12-13 20:07:46
问题 I tried making a quick macro for creating and showing a simple "ok" dialog box in iOS: #define ALERT_DIALOG(title,message) \ do\ {\ UIAlertView *alert_Dialog = [[UIAlertView alloc] initWithTitle:(title) message:(message) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];\ [alert_Dialog show];\ } while ( 0 ) If I try to use it in my code: ALERT_DIALOG(@"Warning", @"Message"); I get the error: Parse Issue. Expected']' And the error seems to be pointing at the second @ right before

VBA: Access to registry while preprocessing

痴心易碎 提交于 2019-12-13 18:10:05
问题 I want to conditionally compile code in one VBAproject, with a condition that depends on some registry-entry. Is this somehow possible in VBA? I know that there are some simple preprocessing possibilites in VBA, but I can not see if it is possible to somehow access the registry while preprocessing. Or Maybe some other possibility to check the registry before compiling. Since I get a compile error because of some missing reference(and thus missing class object), I aim to check the registry

When will this execute?

浪子不回头ぞ 提交于 2019-12-13 10:13:47
问题 I have a C code: ... void caller() { #define YES 1 #define NO 0 } ... Will the both #define lines execute when caller is called/executed, or will they execute at compile-time only. 回答1: The prerpcessor macros don't execute, they are just named fragments of the code which will be replaced by the preprocessor to theirs content if you use them. Read more about preprocessor macros here. So, after preprocessing, your code will be: void caller() { } Let assume you use the YES macro after you

Using variables in the preprocessor directives

一世执手 提交于 2019-12-13 06:31:05
问题 which global variable can be used in the preprocessor directive file.cpp int variable = 1; #if variable >= 1 int a = 0; #else int a = 1; #endif or file.cpp const int variable = 1; #if variable >= 1 int a = 0; #else int a = 1; #endif or file.cpp #include "header.h" // extern in variable; in the header.h #if variable >= 1 int a = 0; #else int a = 1; #endif What are the rules which governs using the variables in the proprocessor directive? If a variable which can be consant folded, can it be

Token pasting in c using a variable that increments

送分小仙女□ 提交于 2019-12-13 04:53:37
问题 I have a set of arrays : msg1[] msg2[] .... msgn[] . And I need to use the values in a while loop. as msgi[] . When I define it as #define MSG(a) msg##a and put it in a loop and increment i , it expands it to msgi ? 回答1: You can't do it that way. Instead you could create a new array, that contains pointers to the actual arrays: int array1[...]; int array2[...]; int *all_arrays[] = { array1, array2 }; 回答2: build your c code with gcc -E myfile.c and you will see the reason this called

Can I make a preprocessor directive dependent on the .NET framework version?

倖福魔咒の 提交于 2019-12-12 08:20:04
问题 Here's a concrete example of what I want to do. Consider the string.Join function. Pre-.NET 4.0, there were only two overloads, both of which required a string[] parameter. As of .NET 4.0, there are new overloads taking more flexible parameter types, including IEnumerable<string> . I have a library which includes a Join function that does essentially what the .NET 4.0 string.Join function does. I was just wondering if I could make this function's implementation dependent on the .NET framework

Why can std::max and std::min still be used even if I didn't #include <algorithm>?

耗尽温柔 提交于 2019-12-12 08:19:51
问题 #include <iostream> int main() { int value1 = 1, value2 = 10; std::cout << "Min = " << std::min(value1,value2) <<std::endl; std::cout << "Max = " << std::max(value1,value2)<< std::endl; } As far as I know, the min and max functions are defined in <algorithm> . If I didn't tell the pre-processor to include <algorithm> why does the code still work? 回答1: Most likely, something inside of iostream has directly or indirectly included some other header that defines std::min and std::max . (Perhaps

bits set by lookup table - Recursive macro [duplicate]

半城伤御伤魂 提交于 2019-12-11 19:19:07
问题 This question already has an answer here : Hint for lookup table set bit count algorithm (1 answer) Closed 6 years ago . static const unsigned char BitsSetTable256[256] = { # define B2(n) n, n+1, n+1, n+2 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2) # define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2) B6(0), B6(1), B6(1), B6(2) }; This code is very famous in set bit problem.. I have understand how it will output a lookup table at compile time. but I need more intuition for this .. means What is

Preprocessor Directives Reflection Injection

…衆ロ難τιáo~ 提交于 2019-12-11 15:41:18
问题 How to inject C# Preprocessor Directives to an interface by Reflection ? Example : I want to inject #if SILVERLIGHT to any WCF service contract interface. 回答1: Short answer: you can't. Slightly longer answer: you question doesn't even make sense in the first place. Preprocessor directives are processed before compilation. The result of that processing is the new, modified, source code. That source code then gets compiled. For example, if the SILVERLIGHT symbol is not defined at the time of