3 ms·
Is this really a useful application of function overloads? Integer promotion is tricky as it stands. Overloading, instead of having the user signal intent expli
by jstimpfle 11y ago
Is this really a useful application of function overloads? Integer promotion is tricky as it stands. Overloading, instead of having the user signal intent explicitly, might increase likelyhood of errors, and make them harder to find.
- panic 11y agoYeah, this doesn't look like something I'd want to have to debug if it breaks.
- foonathan 11y agoEven if you named the functions differently (clz8/16/32/64), you still needed to match them to the appropriate __builtin_clz version.
- jstimpfle 11y agoThe matching itself is not a problem. Arguably it's required for portability, but it's very straightforward. Obvious implementation, all in one place, practically no maintenance cost, very unlikely to break. But think about all the callers of these functions. There are usually more callers, at disparate places, and context will be less narrow there. It's important not to conceal what is intended to happen at the call side. If these functions are overloaded and at some point due to unexpected integer promotion or a crazy typedef the wrong overload is picked, you will have a hard time debugging.
- foonathan 11y agoAnd I've showed one way to do the matching in an automated way. How you wrap those implementation things, is up to you. I agree, overloading might have problems.