612
Find yourself (lemmy.ml)
submitted 8 months ago by coja@lemmy.ml to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] Eufalconimorph@discuss.tchncs.de 19 points 8 months ago
#define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })

GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.

this post was submitted on 22 Oct 2023
612 points (95.7% liked)

Programmer Humor

31215 readers
513 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS