coja@lemmy.ml to Programmer Humor@lemmy.ml · 11 months agoFind yourselflemmy.mlimagemessage-square104fedilinkarrow-up1647arrow-down129
arrow-up1618arrow-down1imageFind yourselflemmy.mlcoja@lemmy.ml to Programmer Humor@lemmy.ml · 11 months agomessage-square104fedilink
minus-squareEufalconimorph@discuss.tchncs.delinkfedilinkarrow-up21·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.
minus-squareEufalconimorph@discuss.tchncs.delinkfedilinkarrow-up1·11 months ago__auto_type is a compiler builtin, not a library function. It’s not a function at all, the parentheses are for precedence & grouping.
#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.
deleted by creator
__auto_type
is a compiler builtin, not a library function. It’s not a function at all, the parentheses are for precedence & grouping.