Max Madness

Determining which is bigger, A or B.

  • C
  • Macros
Written by Mark McKeown • 29 Mar 2018 • 1 min read • Last updated 3 hours ago

A lot of C programmers will recognise this:

#define max(A, B)  ((A) > (B) ? (A) : (B))

It's a macro for determining which is bigger, A or B. It will work for lots of different types and was originally come from The C Programming Language(opens new window) by Kernighan and Ritchie.

There is a really interesting discussion on the “max” macro on LWN, https://lwn.net/Articles/749064/(opens new window) Who knew there was a difference between "constant value" and a "constant expression"!