Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - How to write a macro

I need to write a multi-line macro. I need this because I must have partial code that has been "paste" into specific points in my code. How can I do this?

like image 755
Andrea Mario Lufino Avatar asked Feb 05 '26 02:02

Andrea Mario Lufino


1 Answers

It's not really clear from your question what you actually want, but a plain multi-line macro is defined as follows:

#define FOO something; \
            something_else;

Of course, beware of the if .. else problem. If this is applicable to your case, you could wrap things into a do { ... } while(0) construct. This will ensure that it's treated as a single statement.

#define FOO do                 \
            {                  \
               something;      \
               something_else; \
            } while (0)
like image 196
Lindydancer Avatar answered Feb 07 '26 18:02

Lindydancer