Yes, Larme is right. Macros can be used in many languages, this is not a specialty of objective-c.
Macros are preprocessor definitions. This means that before compiling the code, the preprocessor scans your code and, among other things, replaces the definition of your macro wherever it sees the name of your macro. He does nothing smarter than that.
Almost literal code change. eg.-
Suppose you want a method to return a maximum of two numbers. You are writing a macro to accomplish this simple task:
#define MAX(x, y) x > y ? x : y
Simple, right? Then you use the macro in your code as follows:
int a = 1, b = 2; int result = 3 + MAX(a, b);
EDIT:
The problem is that the preprocessor replaces the macro definition with the code before compilation, so this is the code that the compiler sees:
int a = 1, b = 2; int result = 3 + a > b ? a : b;
In the order of operations, it is required that the sum 3 + a be calculated before applying the triple operator. You intended to keep the 3 + 2 value as a result, but instead, first add 3 + 1 and check if the amount exceeds the amount of 2, which is. So the result is 2, not 5, which you expected.
So, you fix the problem by adding some parentheses and try again:
#define MAX(x, y) ((x) > (y) ? (x) : (y))