609
Find yourself (lemmy.ml)
submitted 11 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 20 points 11 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
609 points (95.8% liked)

Programmer Humor

32054 readers
1536 users here now

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

Rules:

founded 5 years ago
MODERATORS