c-preprocessor

Objective-C use of #import and inheritance

强颜欢笑 提交于 2019-12-22 05:52:22
问题 I have a hypothetical UIViewController class named "foo". foo inherits from class bar and class bar #import's "Class A", a class which foo uses extensively. The problem is, when I'm using an instance of class A in foo, I don't get any compiler errors, but I do get a warning for instance, that an instance of Class A does not respond to a particular method. Do I have to explicitly #import ClassA.h into class 'foo'? even though class foo extends extends bar, which already imports it? Hope that's

Is it possible to sort arrays using preprocessor?

为君一笑 提交于 2019-12-22 05:43:16
问题 I have a number of very long arrays. No run-time sort is possible. It is also time consuming to sort them manually. Moreover, new elements can be added in any order later, so I would like to sort them by value using C preprocessor or maybe there is any compilers flag (GCC)? For example: sometype S[] = { {somevals, "BOB", someothervals}, {somevals, "ALICE", someothervals}, {somevals, "TIM", someothervals}, } must be sorted so: sometype S[] = { {somevals, "ALICE", someothervals}, {somevals,

The subtle difference between #ifdef and #if for a macro defined as 0

五迷三道 提交于 2019-12-22 05:25:29
问题 Given the C file below: $ cat macros.c #ifdef MACRO # error MACRO is defined #else # error MACRO is undefined #endif #if MACRO # error MACRO is non-zero #else # error MACRO is zero #endif What is the expected output of the following? $ gcc -c macros.c $ gcc -DMACRO -c macros.c $ gcc -DMACRO=0 -c macros.c Answer : Here's what the gcc's preprocessor on my machine does. $ gcc -c macros.c macros.c:4:4: error: #error MACRO is undefined macros.c:9:4: error: #error MACRO is zero $ gcc -DMACRO -c

C preprocessor using the closing bracket of a parent macro

孤者浪人 提交于 2019-12-22 05:22:05
问题 I have this code which works: #include <stdio.h> #define A(x) x B #define B(x) C(x, #define C(x,y) y x) int main( void ) { printf( A("1") ("2") "3" ); } It prints 132 (the point of the A macro is to swap the thing which follows its parameters in brackets with everything after that until another closing bracket) But if I use that within another macro: #define Z(x) x printf( Z( A("1") ("2") "3" ) ); I get the compile error "Unterminated function-like macro invocation". I realise that this

Token pasting in C

爱⌒轻易说出口 提交于 2019-12-22 05:15:21
问题 After reading about VA_NARG I tried to implement function overloading depending on number of arguments in C using macros. Now the problem is: void hello1(char *s) { ... } void hello2(char *s, char *t) { ... } // PP_NARG(...) macro returns number of arguments :ref to link above // does not work #define hello(...) hello ## PP_NARG(__VA_ARGS__) int main(void) { hello("hi"); // call hello1("hi"); hello("foo","bar"); // call hello2("foo","bar"); return 0; } I've read this from C-faq. But still

Error when compiling Ruby 1.8.7 from source: math.c:37: error: missing binary operator before token “(”

时光毁灭记忆、已成空白 提交于 2019-12-22 05:09:54
问题 This is really odd: : josh@josh; wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.bz2 : josh@josh; tar xvjf ruby-1.8.7.tar.bz2 : josh@josh; cd ruby-1.8.7/ : josh@josh; CFLAGS='-O0 -g -Wall' ./configure --disable-pthread : josh@josh; make gcc -O0 -g -Wall -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c array.c [...] gcc -O0 -g -Wall -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c math.c math.c: In function ‘domain_check’: math.c:37: error: missing binary operator before token "(" make: *** [math.o]

Variadic macro with no arguments for its variadic parameter

可紊 提交于 2019-12-22 04:17:10
问题 Is it legal to invoke a variadic macro M with no arguments for its variadic parameter? The relevant standard quote is [cpp.replace]/4 : If the identifier-list in the macro definition does not end with an ellipsis, the number of arguments (including those arguments consisting of no preprocessing tokens) in an invocation of a function-like macro shall equal the number of parameters in the macro definition. Otherwise, there shall be more arguments in the invocation than there are parameters in

Define a preprocessor value from command line using MSBuild [duplicate]

烂漫一生 提交于 2019-12-22 01:27:09
问题 This question already has answers here : msbuild, defining Conditional Compilation Symbols (4 answers) Closed 2 years ago . I need to create a demo version of an existing large application consisting of multiple projects. I'd like to use the existing projects, and just neuter the functionality via preprocessor directives #if DEMO mycode.NeuterNow(); #endif We are building our app using MSBuild, and I'd ideally use something along the lines of: MSBuild -DefineProperty:DEMO MySolution.sln Does

Can't use macro define class in C++

非 Y 不嫁゛ 提交于 2019-12-21 20:55:27
问题 I want to generate many sub-class which only has little difference, so I want to use macro to simplify my job. The macro define below: #define DECLARE_SUB_CLASS(sub_class_name, base_class_name, value1) \ class sub_class_name:base_class_name \ { \ public: \ virtual int initialize(const void *); \ virtual int run(const void *); \ virtual void reset(); \ virtual int output(const char*); \ virtual void terminate(); \ private: \ static const char m_szValue=#value1; \ }; I use it like this: DECLARE

Invalid token at start of a preprocessor expression Xcode [duplicate]

匆匆过客 提交于 2019-12-21 20:36:16
问题 This question already has an answer here : Macro in Objective-C calling isEqualToString: produces error about invalid token (1 answer) Closed 3 years ago . #define A7VERSION() ({[[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];}) #define IS_OS_7 A7VERSION()>=7 The above declaration seems to compile well. But as soon as I add it a .m file I get the following exception "invalid token at start of a preprocessor expression". I am not able to