c-preprocessor

C Programming: Preprocessor, include files from macro

青春壹個敷衍的年華 提交于 2019-12-02 04:30:54
If I could find a way to do something similar to this, I could cut out hundreds of lines of code in my application, and dramatically increase maintainability. Anyone have any ideas? #include <stdio.h> int main( ) { #define include_all_files(root) \ #include #root "1.h" \ #include #root "2.h" \ #include #root "3.h" \ #include #root "4.h" include_all_files( first_library ) include_all_files( second_library ) include_all_files( third_library ) return 0; } EDIT : I appreciate the responses, my example seems to be causing a misdirection in effort, so here is the problem I am actually trying to

What's the meaning of “##” in a C++ macro? [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-02 04:28:51
问题 This question already has answers here : What are the applications of the ## preprocessor operator and gotchas to consider? (13 answers) The ## operator in C (7 answers) Closed 6 years ago . What's the meaning of "##" in the following? #define CC_SYNTHESIZE(varType, varName, funName)\ protected: varType varName;\ public: inline varType get##funName(void) const { return varName; }\ public: inline void set##funName(varType var){ varName = var; } 回答1: The operator ## concatenates two arguments

#ifndef in c file?

℡╲_俬逩灬. 提交于 2019-12-02 03:12:37
Is it possible to put #ifndef at the top of a c file? Basically I need to check whether a certain preprocessor constant was declared when running the program and my program will change accordingly. I need to check if -D DESCENDING_ORDER=1 is added as an argument (doesn't matter what value given). I have this code at the top of my main c file: #ifndef DESCENDING_ORDER int ascending = 1; #else int ascending = 0; #endif Works when compiling by itself, but I get errors when I try compiling with a Makefile, something along the lines of "expected identifier before 'int' for int ascending = 1 .

Real-world advantage of namespace aliases vs defines [closed]

橙三吉。 提交于 2019-12-02 02:43:37
EDIT: I'm planing to refactor some code, and replace the define with a namespace alias. I can't do this though just because "macros are evil". I need to explain why I want to make the change and what can go wrong if I don't. Leaving aside the stance that "macros are evil", what are the downfalls of #define over a namespace alias? Take the code #define MY_NAMESPACE my_namespace versus namespace MY_NAMESPACE = my_namespace; The reason for having aliases is not in the scope of the question. You can also assume the name of the namespace is unique enough that it doesn't appear anywhere else (i.e.

What is WINAPI_FAMILY_ONECORE_APP?

牧云@^-^@ 提交于 2019-12-02 02:40:03
I was looking through Microsoft's port of OpenSSL on GitHub. One commit caught my eye, and it was Adding Win10 Universal Platform support . In the commit, a partition called WINAPI_FAMILY_ONECORE_APP showed up. However, I'm not finding much about it when searching. There are two hits in English and 22 hits in Chinese (see below). Following What’s new in Visual Studio Tools for Windows 10 Preview provides some quasi-bullet points with no explanations: new API partition WINAPI_FAMILY_ONECORE_APP ARM 64 Universal CRT ... I have two questions: What is WINAPI_FAMILY_ONECORE_APP , and how is it

print_once, how blockwise it is working?

断了今生、忘了曾经 提交于 2019-12-02 02:06:14
问题 I am trying to understand implement a print once function, this code is working fine; But I am not able to understand some things: 1) How blockwise this is working? Maybe I am not able to clear it properly, but just want to know, what property of C make this happen? 1 #include <stdio.h> 2 3 #define _TRACE_ 4 5 #ifdef _TRACE_ 6 #define print_once(fmt, ...) \ 7 ({ \ 8 static bool __print_once=false; \ 9 if(!__print_once) { \ 10 __print_once = true; \ 11 do { \ 12 printf(fmt, ##__VA_ARGS__); \

What does ## mean in the #define directive in the code here

杀马特。学长 韩版系。学妹 提交于 2019-12-02 02:03:16
问题 Please tell me the answer with explanation: #define f(g,h) g##h main(){ printf("%d",f(100,10)); } 回答1: ## is used to concatenate whatever is before the ## with whatever is after it. It is used for concatenation. You can check the reference for details A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers (which are not macro-expanded first) and then concatenates the result. This operation is called "concatenation" or

print_once, how blockwise it is working?

丶灬走出姿态 提交于 2019-12-02 01:52:32
I am trying to understand implement a print once function, this code is working fine; But I am not able to understand some things: 1) How blockwise this is working? Maybe I am not able to clear it properly, but just want to know, what property of C make this happen? 1 #include <stdio.h> 2 3 #define _TRACE_ 4 5 #ifdef _TRACE_ 6 #define print_once(fmt, ...) \ 7 ({ \ 8 static bool __print_once=false; \ 9 if(!__print_once) { \ 10 __print_once = true; \ 11 do { \ 12 printf(fmt, ##__VA_ARGS__); \ 13 }while(0); \ 14 } \ 15 }) 16 #else 17 #define print_once(fmt, ...) \ 18 printf("\n"); 19 #endif 20 21

What's the meaning of “##” in a C++ macro? [duplicate]

喜你入骨 提交于 2019-12-02 01:49:49
This question already has an answer here: What are the applications of the ## preprocessor operator and gotchas to consider? 13 answers The ## operator in C 7 answers What's the meaning of "##" in the following? #define CC_SYNTHESIZE(varType, varName, funName)\ protected: varType varName;\ public: inline varType get##funName(void) const { return varName; }\ public: inline void set##funName(varType var){ varName = var; } The operator ## concatenates two arguments leaving no blank spaces between them: e.g. #define glue(a,b) a ## b glue(c,out) << "test"; This would also be translated into: cout <

What is defined in Mac OS GCC for C?

折月煮酒 提交于 2019-12-02 01:16:17
问题 So I wonder where to get the list of default Mac OS GCC defines for pure C? Can any one post list here? Why I need such thing: I do not have mac OS X, I try to compile ffmpeg with alchemy GCC under ubuntu, and ffmpeg wonders which os it is. And gives me wornings like from libavformat/os_support.c:28: /home/rupert/Desktop/arch/alchemy-ubuntu-v0.5a/avm2-libc/include/machine/_types.h:95:5: warning: "OSX" is not defined 回答1: With Mac OS X 10.6.7, Xcode 3.2.6 and gcc 4.2.1 I get the following: $