coja@lemmy.ml to Programmer Humor@lemmy.ml · 1 year agoFind yourselflemmy.mlimagemessage-square17fedilinkarrow-up12arrow-down10
arrow-up12arrow-down1imageFind yourselflemmy.mlcoja@lemmy.ml to Programmer Humor@lemmy.ml · 1 year agomessage-square17fedilink
minus-squareEufalconimorph@discuss.tchncs.delinkfedilinkarrow-up1·1 year 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.
#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.