Skip to content

Instantly share code, notes, and snippets.

@JensAyton
Created October 8, 2012 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensAyton/3855499 to your computer and use it in GitHub Desktop.
Save JensAyton/3855499 to your computer and use it in GitHub Desktop.
Some of the macros in NSObjCRuntime.h just aren’t ugly enough.
#undef MIN
#define MIN__(A,B,C) ({ __typeof__(A) __a##C = (A); __typeof__(B) __b##C = (B); __a##C < __b##C ? __a##C : __b##C; })
#define MIN_(A,B,C) MIN__(A,B,C)
#define MIN(A,B) MIN_(A,B,__COUNTER__)
#undef MAX
#define MAX__(A,B,C) ({ __typeof__(A) __a##C = (A); __typeof__(B) __b##C = (B); __a##C < __b##C ? __b##C : __a##C; })
#define MAX_(A,B,C) MAX__(A,B,C)
#define MAX(A,B) MAX_(A,B,__COUNTER__)
#undef ABS
#define ABS__(A,C) ({ __typeof__(A) __a##C = (A); __a##C < 0 ? -__a##C : __a##C; })
#define ABS_(A,C) ABS__(A,C)
#define ABS(A) ABS_(A,__COUNTER__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment