I'm studying sequential set representation, and one of the only lines in the code that i cant figure out is this

#define MAX(a,b)           (((a) > (b)) ? (a) : (b))

i get that MAX if a function with two operators, a and b but i dont really understand the second part

9 Years
Discussion Span
Last Post by Dewey1040

The syntax is called a ternary operator. It acts on 3 "things".
condition ? do something if condition is true : do something if condition is false.
It is some kind of "shorthand" which is quite handy when defining macros.


thanks to both of you, i kinda figured it would return the higher number since the name of the macro is MAX, i just didnt know how to interpret the ? and : symbols

heres a second one in the same program but i think i understand it

#define member_count(p_S) ((p_S) -> free - (p_S) -> base)

this macro will return the free field distance from the 0th element of the struct you pass to it minus the base field distance from the 0th element of that same struct.

^i dont know how to word that any better

base = 0.......free = 5

so it would return 5

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.