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

MAX is not a function -- it is a macro. The macro says if a is greater than b then return a otherwise return b.

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

[4][3][88][5][1][][][][][][]
^...................^
base = 0.......free = 5

so it would return 5

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.