preprocessor-directive

Function overloading in C using GCC - functions with mutiple arguments

耗尽温柔 提交于 2020-01-05 11:14:10
问题 In a previous question I found a way to overload functions in C99 when each function only took a single argument. See the answers in: Function overloading in C using GCC - compiler warnings for details. Now that I've found a way to do it with single argument functions I'm wondering how this can be done for functions that take multiple arguments. I assume it will have something to do with __VA_ARGS__ and using ... but I can't seem to find anything that works or even wants to compile. This will

C++ and preprocessor macros: variadic type

只谈情不闲聊 提交于 2020-01-04 08:22:53
问题 Take for example the following macro: #define _CREATE_VAR(X1) double X1{smc::define_variable (data, X1, #X1)}; #define _CREATE_VAR2(X1,X2) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / #define _CREATE_VAR3(X1,X2,X3) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / double X3{smc::define_variable (data, X3, #X3)}; / #define _CREATE_VAR4(X1,X2,X3,X4) double X1{smc::define_variable (data,

C++ and preprocessor macros: variadic type

♀尐吖头ヾ 提交于 2020-01-04 08:20:03
问题 Take for example the following macro: #define _CREATE_VAR(X1) double X1{smc::define_variable (data, X1, #X1)}; #define _CREATE_VAR2(X1,X2) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / #define _CREATE_VAR3(X1,X2,X3) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / double X3{smc::define_variable (data, X3, #X3)}; / #define _CREATE_VAR4(X1,X2,X3,X4) double X1{smc::define_variable (data,

#define, #ifdef #undef #endif

青春壹個敷衍的年華 提交于 2020-01-04 06:34:26
问题 I have the following code #define PROC_ADD void main(void) { while(1) { #ifdef PROC_ADD // Do this code here then undefined it to run the code in the else // processing work #undef PROC_ADD #else // now that PROC_ADD has been undefined run this code // processing work #endif } } However, it will run the code. But it won't run the code in the else after the PROC_ADD has been undefined. I think the reason could be that you can only define and undefine at compile time, and not at run-time.

Can #define preprocessor directive contain if and else?

我的未来我决定 提交于 2020-01-03 05:06:07
问题 I was trying the logger code from this link, but it gives me error. How to implement a good debug/logging feature in a project #ifndef _LOGGER_HPP_ #define _LOGGER_HPP_ #include <iostream> #include <sstream> /* consider adding boost thread id since we'll want to know whose writting and * won't want to repeat it for every single call */ /* consider adding policy class to allow users to redirect logging to specific * files via the command line */ enum loglevel_e {logERROR, logWARNING, logINFO,

Use a template parameter in a preprocessor directive?

混江龙づ霸主 提交于 2019-12-30 06:25:23
问题 Is it possible to use a non-type constant template parameter in a preprocessor directive? Here's what I have in mind: template <int DING> struct Foo { enum { DOO = DING }; }; template <typename T> struct Blah { void DoIt() { #if (T::DOO & 0x010) // some code here #endif } }; When I try this with something like Blah<Foo<0xFFFF>> , VC++ 2010 complains something about unmatched parentheses in the line where we are trying to use #if . I am guessing the preprocessor doesn't really know anything

Create multiple versions of a project in Visual Studio using Build Configurations

狂风中的少年 提交于 2019-12-29 07:01:14
问题 I neeed to create multiple versions of my project using configuration just like we do with #define , #if , #endif . The down side of using these preprocessor directives is that I need to define symbols in almost every file of the project but I want to handle this thing by my build configurations. I am not even sure if Build Configurations will help me to do this. What I want is if I create a configuration with name "Development" and other with name "QA", my code would look like: if

Making something both a C identifier and a string?

旧巷老猫 提交于 2019-12-29 03:21:12
问题 Say you want to generate a matched list of identifiers and strings enum { NAME_ONE, NAME_TWO, NAME_THREE }; myFunction(NAME_ONE, "NAME_ONE"); myFunction(NAME_TWO, "NAME_TWO"); myFunction(NAME_THREE, "NAME_THREE"); ..without repeating yourself, and without auto-generating the code, using C/C++ macros Initial guess: You could add an #include file containing myDefine(NAME_ONE) myDefine(NAME_TWO) myDefine(NAME_THREE) Then use it twice like: #define myDefine(a) a, enum { #include "definitions" }

How are the __cplusplus directive defined in various compilers?

橙三吉。 提交于 2019-12-28 12:16:42
问题 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? 回答1: 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

Using X-lists and preprocessor directives to generate configurable C Code At compile time

我只是一个虾纸丫 提交于 2019-12-25 08:47:41
问题 I have a codebase already containing repetitive code, with only minor differences, serializable ID-s, indexes, variable arrays. The codebase is huge, and some components are being activated/deactivated based on simple preprocessor directives and constants(e.g.: #define CFG_PROJECT cfgAutobot , #define CFG_PROJECT cfgUltron , ..etc). The functionality is effectively the same, but with varying components and conditionals. Example: int somedata; int somecounter; void main_loop(){ #if(CFG_PROJECT