preprocessor-directive

How are the __cplusplus directive defined in various compilers?

こ雲淡風輕ζ 提交于 2019-11-28 08:06:21
My compiler expands it to 199711L. What does that mean? I read that __cplusplus > 199711L signifies C++11. What are the possible expansions of this macro and what does it signify? The 199711L stands for Year=1997, Month = 11 (i.e., November of 1997) -- the date when the committee approved the standard that the rest of the ISO approved in early 1998. For the 2003 standard, there were few enough changes that the committee (apparently) decided to leave that value unchanged. For the 2011 standard, it's required to be defined as 201103L, (again, year=2011, month = 03) again meaning that the

C Preprocessor testing definedness of multiple macros

[亡魂溺海] 提交于 2019-11-28 07:58:29
I searched the site but did not find the answer I was looking for so here is a really quick question. I am trying to do something like that : #ifdef _WIN32 || _WIN64 #include <conio.h> #endif How can I do such a thing? I know that _WIN32 is defined for both 32 and 64 bit windows so I would be okay with either for windows detection. I am more interested in whether I can use logical operators like that with preprocessor directives, and if yes how, since the above does not work. Compiling with gcc I get : warning: extra tokens at end of #ifdef directive , and it basically just takes the first

Is there a preprocessor directive for detecting C++11x support? [duplicate]

不羁岁月 提交于 2019-11-28 06:09:49
This question already has an answer here: How do I check for C++11 support? 10 answers If have some code where I would like to use C++11x extensions as much as possible, but have a fallback if this is not supported. Currently the OSX version of GCC and the VisualC compiler has little to no support for C++11x, so I use: #if (defined(__APPLE__) || (defined(_WIN32))) ...fallback code without C++11x ... #else ... code using C++11x ... #endif And this works, but is not really the right thing to do, especially since the gcc compiler in MacPorts DOES support c++11x. Is there a #define C11X_SUPPORTED

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

末鹿安然 提交于 2019-11-27 18:54:43
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? Armen Tsirunyan 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 --------| Yes, you can nest #if / #endif blocks. Some C coding styles would tell you to write #ifdef CONDITION1 # ifdef CONDITION2 # endif

When to use preprocessor directives in .net?

不打扰是莪最后的温柔 提交于 2019-11-27 17:14:25
问题 I think this is a simple question so I assume I'm missing something obvious. I don't really ever use preprocessor directives but I was looking at someone's code which did and thought it was something I should be familiar with. So I looked at the msdn example here it has the code: #define DEBUG // ... #if DEBUG Console.WriteLine("Debug version"); #endif My two questions are: in the example above why do they define DEBUG? I was under the impression that was set if you compile in debug v.

Preprocessor macro expansion to another preprocessor directive

回眸只為那壹抹淺笑 提交于 2019-11-27 16:33:16
问题 Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask: Can a preprocessor macro, for instance in #include "MyClass.h" INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass) expand to another include, like in #include "MyClass.h" #include "FooTemplate.h" template class FooTemplate<MyClass>; ? 回答1: I believe that cannot be done, this is because the pre-processor is single pass . So it cannot emit other preprocessor directives.

Force the compiler to ignore some lines in the program

你。 提交于 2019-11-27 11:26:19
问题 Suppose that I have 10,000 lines of C++ code. 200 lines of this code are for testing purpose (for example, check the program and show an error message). Is there an way in C++ to ignore or consider some lines of the code (maybe with preprocessor keywords)? 回答1: Short answer: Use macros and #ifdef checking. For example: #ifdef MY_CONTROL_MACRO ... #endif the code within this scope will only be compiled if you already defined the MY_CONTROL_MACRO macro. More stuff: To define such a macro, you

C++ compile time macros to detect windows os

僤鯓⒐⒋嵵緔 提交于 2019-11-27 07:10:30
问题 Are there any C++ compile time macros which exists to detect which Windows OS the code is being compiled on. I basically want to support certain functions only on Win7. So I am interested in doing something like this #if <os_macro> = WIN7 // This function would do something valid only on Win7 builds. bool myfunction { // do something here } #else // This function would typically return false, since its not supported on OS below win7 bool myfunction { return false; } #endif Is there any other

Try statement in Cython for cimport (for use with mpi4py)

最后都变了- 提交于 2019-11-27 06:32:56
问题 Is there a way to have the equivalent of the Python try statement in Cython for the cimport? Something like that: try: cimport something except ImportError: pass I would need this to write a Cython extension that can be compiled with or without mpi4py. This is very standard in compiled languages where the mpi commands can be put between #ifdef and #endif preprocessor directives. How can we obtain the same result in Cython? I tried this but it does not work: try: from mpi4py import MPI from

C Preprocessor testing definedness of multiple macros

半城伤御伤魂 提交于 2019-11-27 02:07:15
问题 I searched the site but did not find the answer I was looking for so here is a really quick question. I am trying to do something like that : #ifdef _WIN32 || _WIN64 #include <conio.h> #endif How can I do such a thing? I know that _WIN32 is defined for both 32 and 64 bit windows so I would be okay with either for windows detection. I am more interested in whether I can use logical operators like that with preprocessor directives, and if yes how, since the above does not work. Compiling with