c-preprocessor

Preprocessor macro for Apple Watch?

随声附和 提交于 2020-01-12 13:49:06
问题 I was looking at Apple's Lister (for Apple Watch, iOS, and OS X) sample. The sample performs a test for iOS and OS X: #import <TargetConditionals.h> #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) @import ListerKit; #elif TARGET_OS_MAC @import ListerKitOSX; #endif However, there is no test for TARGET_OS_WATCH or similar. Grepping for watch in TargetConditionals.h delivers no hits: $ cat /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer /SDKs/iPhoneOS7.1.sdk

Portably detect __VA_OPT__ support?

只愿长相守 提交于 2020-01-12 02:50:29
问题 In C++20, the preprocessor supports __VA_OPT__ as a way to optionally expand tokens in a variadic macro if the number of arguments is greater than zero. (This obviates the need for the ##__VA_ARGS__ GCC extension, which is a non-portable and ugly hack.) Clang SVN has implemented this feature, but they haven't added a feature test macro for it. Can any clever preprocessor hacker figure out a way to detect the presence or absence of __VA_OPT__ support without causing a hard error or a

Wrapping functions with macros (without renaming) C

↘锁芯ラ 提交于 2020-01-11 14:14:06
问题 Im interested to add in some extra logic around existing function calls, by wrapping them without renaming them. (just for a test) . The existing solutions I found rely on wrapping a function in a macro of a different name, which can mean changing a lot of code. Any suggestions? Note, I'm aware of LD_PRELOAD , but am interested to use macro's to be able to inspect the arguments passed to the function (using _Generic for example). 回答1: There's normally no need to rename macro-wrapped functions

C Programming: Preprocessor, include files from macro

家住魔仙堡 提交于 2020-01-11 12:39:30
问题 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

C Programming: Preprocessor, include files from macro

♀尐吖头ヾ 提交于 2020-01-11 12:39:10
问题 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

Syntax error while using a #define in initializing an array, and as arguments to a function in C? [closed]

霸气de小男生 提交于 2020-01-11 12:34:07
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Using a #define while initializing an array #include <stdio.h> #define TEST 1; int main(int argc, const char *argv[]) { int array[] = { TEST }; printf("

Macros as arguments to preprocessor directives

你。 提交于 2020-01-11 09:35:08
问题 Being faced with the question whether it's possible to choose #include s in the preprocessor I immediately thought not possible . .. Only to later find out that it is indeed possible and you only need to watch out for argument expansions (which e.g. Boost.Preprocessor can take care of). While I'd avoid actually doing that for includes if possible, I'd like to know why this works. At the moment I fail to get a useful understanding in the C++ or C standard. Are parameterized macros allowed for

C/C++ #define Macro inside macro?

白昼怎懂夜的黑 提交于 2020-01-11 08:36:09
问题 I would like something like: #define C_OR_CPP(C__, CPP__) #ifdef __cplusplus\ CPP__\ #else\ C__\ #endif Is it possible? Maybe some dirty hack with #include ? Reason: I make a header where a struct uses a member variable of type vector<stuff>* , but in C i want it to simply be void* , you know. TIA 回答1: What's the problem with #ifdef __cplusplus #define C_OR_CPP(C, CPP) CPP #else #define C_OR_CPP(C, CPP) C #endif (Leaving names with double underscore to the implementation per phresnel remark)

Proper C preprocessor macro no-op

£可爱£侵袭症+ 提交于 2020-01-11 08:30:11
问题 For debug logging, I have often seen and used something like #ifdef DEBUG #define DLOG(fmt, args...) printf("%s:%d "fmt,__FILE__,__LINE__,args) #else #define DLOG(fmt, args...) #endif but in a number of places, I have seen the second #define replaced with #define DLOG(fmt, args...) do {} while (0) In particular, there's this answer, and the comment on this other answer to the same question suggests that the problem would be in a situation like if (condition) DLOG("foo"); though my quick test

Preprocessor: Concatenate string to each argument in __VA_ARGS__

狂风中的少年 提交于 2020-01-11 06:31:13
问题 I'd like to append a stringified macro argument to each element in a variadic macro. I think I know what I need, but I couldn't come up with a working solution just yet. Given a variadic macro like: #define FIELD_DECLARATION(NAME, OTHER_FIELD, ...) FIELD_DECLARATION(First, Thing) FIELD_DECLARATION(Second, Thing, Thing, Nothing) I'd like to generate: field_First = {ThingArg}; field_Second = {ThingArg, ThingArg, NothingArg}; I guess what I need is to recursively keep expanding __VA_ARGS__ until