c-preprocessor

#if DEBUG directive in compiled class library

非 Y 不嫁゛ 提交于 2019-12-12 05:06:01
问题 I am going to use #if DEBUG directive in a class library. The compiled ClassLibrary.dll will be used in a separate Application.exe. Will my debug code from this class library be executed in the following situations? library is compiled in DEBUG mode, application is compiled in RELEASE library is compiled in RELEASE, application is compiled in DEBUG 回答1: A compiler directive is interpreted at compile time and not at runtime. Therefore it does not matter, if the using application is compiled in

Doxygen does not see the description of a pre-processor symbol

感情迁移 提交于 2019-12-12 04:30:37
问题 Please do not mind the strangeness of the following minimal example (I would have to make it much larger to justify why I am doing things this way): File test.cpp: #include "a.h" int main() { return 0; } File a.h: namespace N { // without namespace all is well! #include "b.h" } File b.h: /// \file /// Documentation of CMD #define CMD 5 Doxygen 1.8.11 complains: warning: Member CMD (macro definition) of file a.h is not documented. Why doesn't Doxygen see the description of CMD and how do I fix

Omitting code: Any difference between Conditional Attribute and pre-processing directive?

匆匆过客 提交于 2019-12-12 04:08:37
问题 I am wondering what the difference is between #define MYSYMBOL #if MYSYMBOL public void foo () { // ... } #endif and #define MYSYMBOL [Conditional("MYSYMBOL")] public void foo () { // ... } ? Maybe it's obvious but if someone could give me a hint in the right direction I would be thankful :) 回答1: They are different. Using #if removes the enclosed code altogether, so any code that calls the method won't compile because the method has disappeared. You can also wrap any amount of code this way,

Use multiple macros in a macro definition

…衆ロ難τιáo~ 提交于 2019-12-12 03:47:36
问题 I'm trying to use multiple macros in the definition of another macro, but seem to have problems concatenating them together. Here's a very simplified version of what I'm trying to do: #include <stdio.h> #define PICK_SET_A #ifdef PICK_SET_A #define SET A #endif #ifdef PICK_SET_B #define SET B #endif #define ENABLE_VAR_1_A 1 #define ENABLE_VAR_2_A 1 #define ENABLE_VAR_1_B 0 #define ENABLE_VAR_2_B 0 #define MACRO_RESOLVE(var,set) ENABLE_VAR_##var##_##set #define ENABLE_VAR_1 MACRO_RESOLVE(1, SET

How to typecast preprocessor (macros) to output int

穿精又带淫゛_ 提交于 2019-12-12 03:19:50
问题 I have a very simple macro for which I want to typecast its output to int only. How to do that? #define Numbits(A) (sizeof(A)*CHAR_BIT) I tried: #define int Numbits(A)({int val; val = sizeof(A)*CHAR_BIT; return val;}) but it also doesn't work 回答1: Are you saying that #define Numbits(A) (int)(sizeof(A)*CHAR_BIT) didn't work? 来源: https://stackoverflow.com/questions/31443484/how-to-typecast-preprocessor-macros-to-output-int

Multiple Definitions of Same #define Macro in Required Libraries

◇◆丶佛笑我妖孽 提交于 2019-12-12 03:15:58
问题 Two of the libraries I am including share the same definition of a macro in each of their respective .h files. #define MAX <some value> //first definition of MAX in a file #define MAX <some other value> //second definition of MAX in a *different* file and in compilation I get .../httpd.h:43:1: warning: "MAX" redefined and .../opencv2/core/types_c.h:272:1: warning: this is the location of the previous definition I've checked each of these headers, and they have the #include guards. What is the

What is wrong with following C code? [duplicate]

只谈情不闲聊 提交于 2019-12-12 03:15:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Confused about C macro expansion and integer arithmetic A riddle (in C) The expected output of the following C program is to print the elements in the array. But when actually run, it doesn't do so. #include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; } 回答1:

Error when checking the OS on C++ header file

孤街醉人 提交于 2019-12-12 03:12:08
问题 I have received some C++ code that I am trying to compile under Linux 64 bits using the provided makefiles. In that code there is a string_hash.h file containing the code: #ifndef STRING_HASH #define STRING_HASH #include <string> #include "universal_hash_map.h" #ifdef WINDOWS typedef stdext::hash_compare<std::string> String_Hasher; typedef stdext::hash_map< std::string, std::string, stdext::hash_compare<std::string> > String_Hash; #else #ifdef LINUX class String_Hasher: public stdext::hash<

Using BOOST_PP_SEQ_FOREACH_R to recursively process enums

匆匆过客 提交于 2019-12-12 02:57:39
问题 Related to my question Alternative to expanding templates in a switch statement trying to get Boost.Preprocessor to do a nested interation over a sequence. #include <boost/preprocessor.hpp> #include <iostream> #define LASERTYPE_VALUES (EXCIMER)(GAS)(METALVAPOR)(SOLIDSTATE)(DYE)(SEMICONDUCTOR)(FREEELECTRON)(OTHER) enum LaserType { BOOST_PP_SEQ_ENUM(LASERTYPE_VALUES) }; #define LT_NESTED(maR, maToplevelType, maNestedType) \ std::cout << "Test nested: first=" << LaserType(maToplevelType) << "

How to does a variable argument Functioncall as macro define?

余生颓废 提交于 2019-12-12 02:39:02
问题 Imagine, I have a debug source file, which is like this: #if _OWN_DEBUG_LEVEL != 0 void DebugLogMsg (DebugStruct_t *DebugStruct, size_t sizeID, char const *szFormat, ...); #else #define DebugLogMsg(_Expression1, _Expression2, _Expression3) ((void)0) #endif In this case I do not really care about the additional arguments to the function, but what about this case? #if _OWN_DEBUG_LEVEL > 0 #undef DebugLogMsg1 #define DebugLogMsg1(_Expression1, _Expression2, _Expression3) \ DebugLogMsg(