c-preprocessor

How does C++ Preprocessors work?

假装没事ソ 提交于 2021-01-30 09:08:48
问题 I am currently looking at open source C++ projects to learn more about C++. One of the project I am look at is located at: https://github.com/Myzilla-Web-Resources/OpenBlox/ I understand most of the source, but something I don't understand is how he is using the Preprocessors to declare a C++ class. For instance, static_init.h #define DECLARE_STATIC_INIT(ClassName) \ static void static_init_func(); \ static OpenBlox::static_init_helper ClassName##_static_init_helper namespace OpenBlox{ class

How does C++ Preprocessors work?

筅森魡賤 提交于 2021-01-30 09:07:41
问题 I am currently looking at open source C++ projects to learn more about C++. One of the project I am look at is located at: https://github.com/Myzilla-Web-Resources/OpenBlox/ I understand most of the source, but something I don't understand is how he is using the Preprocessors to declare a C++ class. For instance, static_init.h #define DECLARE_STATIC_INIT(ClassName) \ static void static_init_func(); \ static OpenBlox::static_init_helper ClassName##_static_init_helper namespace OpenBlox{ class

How does C++ Preprocessors work?

天大地大妈咪最大 提交于 2021-01-30 09:07:10
问题 I am currently looking at open source C++ projects to learn more about C++. One of the project I am look at is located at: https://github.com/Myzilla-Web-Resources/OpenBlox/ I understand most of the source, but something I don't understand is how he is using the Preprocessors to declare a C++ class. For instance, static_init.h #define DECLARE_STATIC_INIT(ClassName) \ static void static_init_func(); \ static OpenBlox::static_init_helper ClassName##_static_init_helper namespace OpenBlox{ class

Check if a constructed constant is #define'd

守給你的承諾、 提交于 2021-01-28 13:46:24
问题 I am trying to build a test that checks if a certain file defines a header guard with a certain namespace. Because the test is generic, this namespace is only known at compile-time and passed in as -DTHENAMESPACE=BLA . We then use some magic from https://stackoverflow.com/a/1489985/1711232 to paste that together. This means I want to do something like: #define PASTER(x, y) x##_##y #define EVALUATOR(x, y) PASTER(x, y) #define NAMESPACE(fun) EVALUATOR(THENAMESPACE, fun) #ifndef NAMESPACE(API_H)

Documenting conditional exclusive code in Doxygen

谁说我不能喝 提交于 2021-01-28 12:36:05
问题 Consider // EXTERNAL_MACRO is an external macro defined to some value by build system #if EXTERNAL_MACRO == 1 # define EXCLUSIVE_MACRO_ONE #elif EXTERNAL_MACRO == 2 # define EXCLUSIVE_MACRO_TWO #else # define EXCLUSIVE_MACRO_OTHER #endif At built time, only one of the EXCLUSIVE_MACRO_... macros is defined. How can one document all three EXCLUSIVE_MACRO_... macros in Doxygen? PREDEFINED configuration setting is not helpful for this because it allows to define EXTERNAL_MACRO to only a single

Documenting conditional exclusive code in Doxygen

你离开我真会死。 提交于 2021-01-28 12:35:37
问题 Consider // EXTERNAL_MACRO is an external macro defined to some value by build system #if EXTERNAL_MACRO == 1 # define EXCLUSIVE_MACRO_ONE #elif EXTERNAL_MACRO == 2 # define EXCLUSIVE_MACRO_TWO #else # define EXCLUSIVE_MACRO_OTHER #endif At built time, only one of the EXCLUSIVE_MACRO_... macros is defined. How can one document all three EXCLUSIVE_MACRO_... macros in Doxygen? PREDEFINED configuration setting is not helpful for this because it allows to define EXTERNAL_MACRO to only a single

generate a name for macro with another macro (c preprocessor) [duplicate]

只谈情不闲聊 提交于 2021-01-28 12:31:56
问题 This question already has answers here : Macro-producing macros in C? (6 answers) Closed 5 years ago . I can generate name for a function using an macro which is taken from C pre-processor defining for generated function names . #define POSTFIX _ABC //_ABC should be mentioned only there #define PROTOTYPENAME(symbol) symbol ## POSTFIX #define PROTOTYPENAMED(sym) PROTOTYPENAME(sym) int PROTOTYPENAMED(Function)(int a, int b, int c); Above would result as int Function_ABC(int a, int b, int c); If

generate a name for macro with another macro (c preprocessor) [duplicate]

馋奶兔 提交于 2021-01-28 12:18:54
问题 This question already has answers here : Macro-producing macros in C? (6 answers) Closed 5 years ago . I can generate name for a function using an macro which is taken from C pre-processor defining for generated function names . #define POSTFIX _ABC //_ABC should be mentioned only there #define PROTOTYPENAME(symbol) symbol ## POSTFIX #define PROTOTYPENAMED(sym) PROTOTYPENAME(sym) int PROTOTYPENAMED(Function)(int a, int b, int c); Above would result as int Function_ABC(int a, int b, int c); If

How to split this into header and source files?

最后都变了- 提交于 2021-01-28 04:40:16
问题 I have some C code I'd like to split into a header file and a source file: #ifndef BENCHMARK_H #define BENCHMARK_H #ifdef WIN32 #include <windows.h> double get_time() { LARGE_INTEGER t, f; QueryPerformanceCounter(&t); QueryPerformanceFrequency(&f); return (double)t.QuadPart/(double)f.QuadPart; } #else #include <sys/time.h> #include <sys/resource.h> double get_time() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } #endif #endif What would be

Can you use a.b notation in a #define macro name?

送分小仙女□ 提交于 2021-01-28 04:28:41
问题 I want to declare a define, using Visual Studio 2008 or 2010, like that: #define a.b c.d and I get following error: error C2008: '.' : unexpected in macro definition I see that I am allowed to create a define like this: #define a c.d Is the a.b notation supposed to be allowed in the macro name? 回答1: Macros has same set of rules for naming, as do identifiers. In fact, macro-names are identifiers. So, They cannot contain dot. They can consist of only alphabet, digits, and underscore. Nothing