Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Macros vs Inlines

Name: Anonymous 2011-10-15 4:05

Why do so many C programmers define stuff like min and max as macros?

I see stuff like #define MIN(a, b) (a < b ? a : b) everywhere, but then you get issues if you do stuff like MIN(a++, b--). If MIN was an inline function you wouldn't get undefined behavior like that.

Is it because C doesn't have overloadable functions, so you can't define a single MIN that works with every type of number?

Name: Anonymous 2011-10-15 6:52

>>1
if you do stuff like [code]MIN(a++, b--)[/code[o]
[/o]You don't because the all-caps name reminds you that it's a macro and you shouldn't put expression with side-effects in its invocation. Alternatively, you can use Amplified C[sup]http://voodoo-slide.blogspot.com/2010/01/amplifying-c.html[/sup].

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List