preprocessor-directive

Why doesn't my simple C macro work?

江枫思渺然 提交于 2019-12-11 04:45:15
问题 I want to make a simple macro that calls printf() twice like this #ifdef ENABLE_DEBUGPRINTF #define DEBUGPRINTF(msg) printf("At sim_time = %f:", sim_time); printf(msg); #else #define DEBUGPRINTF(msg) //evalutes to nothing #endif Now when I call DEBUGPRINTF("Processed event type: %d with value %f\n", id, data) It prints the first part "At sime_time = ... " correctly but the latter part where it says "Processed events ... " prints the value for id and data incorrectly. Meanwhile printf(

Can #if pre-processor directives be nested in C++?

孤者浪人 提交于 2019-12-11 04:28:10
问题 I have a question about Pre-processor directives in c++: For example: #ifndef QUESTION //some code here #ifndef QUESTION //some code here #endif #endif Can we use it in this way, and can the C++ compiler match the ifndef and endif in the right way? 回答1: Yes, we can. The #endif statement matches to the previous #if #ifdef or #ifndef etc for which there hasn't been a corresponding #endif . e.g. #if ----------| #if -----| | #endif ---| | #endif --------| 回答2: Yes, you can nest #if / #endif

#if inside #define?

混江龙づ霸主 提交于 2019-12-10 13:37:08
问题 I'm sitting on some legacy code that generates a lot of code through #defines. Now I know it's not possible to have an #ifdef inside a #define , but is an #if possible? I would like to do add some specialization for a specific type. (without making major changes like using templates instead). The following sample gives me cryptic errors so this is not the way: #define MK_GET(type) \ type get_ ## type (int index) \ { \ #if type == double \ <-- what i want to add specialized code... \ #endif ..

How to poison an identifier in VC++?

做~自己de王妃 提交于 2019-12-09 11:37:42
问题 Function poisoning is very useful technique in C++. In general it refers to making a function unusable, e.g. if you want to ban the use of dynamic allocation in a program you could "poison" the malloc function so it can't be used. 'Poisoning' an identifier means that any reference to the identifier after the 'poisoning' is a hard compiler error For example (See live demo here) #include <iostream> #include <cstdlib> #pragma GCC poison malloc int main() { int* p=(int*)malloc(sizeof(int)); //

-Werror causes compiler to stop on #warning. What can I do to prevent this?

吃可爱长大的小学妹 提交于 2019-12-09 11:13:38
问题 First off, I want it to stop on warnings. But I also want to print out some informative messages (like "Come back and implement this!"). Unfortunately, my compiler doesn't support #info , #message , #pragma message() , etc. I know there's -Wno-error=<something> , but my google-foo is weak, and I can't seem to find out the <something> for #warning . I've tried -Wno-error=warning , and that just says "there's no -Wwarning ". Same with " warn ". Any suggestions? For what its worth, I'm using the

Can the pre-processor directives like #include be placed only at the top of the program code?

最后都变了- 提交于 2019-12-07 09:46:12
问题 I have used the #pragma directive inside functions without error or warning(especially #pragma pack() ).But the following code shows the warning incompatible implicit declaration of built-in function 'printf'| : int main(void) { printf("Trial"); } #include<stdio.h> Further, here's is an extract from a book I have.The author has bad reviews on SO,especially for his generous use of void main() ,but still I feel no author can be that bad to claim the following without reason: Each of these

Visual Studio: How to use platform toolset as preprocessor directive?

佐手、 提交于 2019-12-07 00:39:27
问题 I have two platform toolsets: v110 and v110_xp for my project, and depending on the chosen platform I want to include/exclude part of the code to be compiled. _MSC_FULL_VER and $(PlatformToolsetVersion) have exactly the same value for both of these platform toolsets. Alternatively, I tried to use $(PlatformToolset) as follows: _MSC_PLATFORM_TOOLSET=$(PlatformToolset) but the problem is that $(PlatformToolset) is non-numeric. Was wondering how can I use this non-numeric value as a preprocessor

XCode syntax highlighting in both conditions of preprocessor #if #else

时间秒杀一切 提交于 2019-12-06 09:50:47
问题 My app uses a lib that won't build and/or run on a simulator so I effectively stubbed out the references to that lib by surrounding references with preprocessor directives like so: #if !(TARGET_IPHONE_SIMULATOR) //Do the real implementation #else //Do a dummy implementation for testing XCode automatically checks to see what my current target is and evaluates the #if/#else which I guess is kind of nice. The problem is, it turns off syntax highlighting, autocomplete, etc for whichever condition

Are there any preprocessor directives that control loop unrolling?

微笑、不失礼 提交于 2019-12-05 22:21:43
问题 Furthermore, how does the compiler determine the extent to unroll a loop, assuming all operations in the loop are completely independent of other iterations. 回答1: For MSVC there is only a vector independence hint: http://msdn.microsoft.com/en-us/library/hh923901.aspx #pragma loop( ivdep ) For many other compilers, like Intel/ibm, there a several pragma hints for optimizing a loop: #pragma unroll #pragma loop count N #pragma ivdep There is a thread with MSVC++ people about unroll heuristic:

XCode syntax highlighting in both conditions of preprocessor #if #else

南笙酒味 提交于 2019-12-04 15:44:51
My app uses a lib that won't build and/or run on a simulator so I effectively stubbed out the references to that lib by surrounding references with preprocessor directives like so: #if !(TARGET_IPHONE_SIMULATOR) //Do the real implementation #else //Do a dummy implementation for testing XCode automatically checks to see what my current target is and evaluates the #if/#else which I guess is kind of nice. The problem is, it turns off syntax highlighting, autocomplete, etc for whichever condition is not going to be compiled. (For example if my current target is the simulator, the code inside the