Ray's Knowledge Base
Unlock

Avoid ARG_MAX as a C++ enumerator on macOS

PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

An enum declaration using ARG_MAX fails to compile on macOS.

Cause#

<limits.h> defines ARG_MAX as a macro, which expands inside the enum declaration.

Fix#

Use a non-colliding enumerator such as ARGMAX, with ARGMIN as its matching name. Do not depend on undefining a system macro.

Evidence#

Observer inbox 5f2574cd39 reports this collision during dftracer-utils work and recommends the renamed enumerators. It does not establish that ARG_MIN itself is a system macro and does not preserve the exact compiler diagnostic.

Also found by searching

  • enum class Op { ARG_MIN, ARG_MAX }; -> error: expected identifier on macOS, expanded from macro 'ARG_MAX'
  • an enum with an ARG_MAX member compiles on Linux but breaks the build on my Mac
  • what should I name argmax and argmin enumerators in C++ to avoid clashing with system headers?
  • limits.h defines ARG_MAX macro on Darwin, collides with enumerator, #undef ARG_MAX workaround?
  • error: expected identifier in enum with ARG_MAX on macOS, enum { ARG_MAX, ARG_MIN }
  • C++ enumerator named ARG_MAX does not compile on Mac
  • why does my enum value ARG_MAX collide with limits.h?
  • macro from <limits.h> expands inside enum declaration, name argmax argmin reducer