News for hackers. Stuff that matters.
Re:Modern programming languages require generics by adrianN on Tuesday May 24, 2022 @01:31PM (#31495046)
Okay, but as far as I know "inline" is just a suggestion for the compiler. Depending on the complexity of the function or the phase of the moon the compiler can choose not to inline it. I wouldn't want to rely on that for a critical piece of my performance.
Re:Modern programming languages require generics by flohofwoe on Tuesday May 24, 2022 @01:36PM (#31495113)
True, that's what I mean with depending too much on the optimizer (in a sibling comment). But IME the threshold for inlining code is surprisingly big (which of course also has a downside: potential code bloat).

I added a little fix which prevents the compiler from discarding the result completely (just by going through __builtin_printf()):

https://godbolt.org/z/W93WrhbaE

PS: another minor tweak (make the comparison function static, so that no extra copy is included in the compiler output):

https://godbolt.org/z/5TTM4x193

Re:Modern programming languages require generics by evmar on Tuesday May 24, 2022 @02:26PM (#31495775)
`static` also allows it to optimize, and it's more of a code hygiene thing. Your original code as written unintentionally defines `find` as a function that must be preserved (as a separate function) into the compiled output, and `static` undoes that.