28 ms·
> * uniform function call syntax that is : a.foo(b) vs foo(a, b) being interchangeable. Herb Sutter has proposed this: https://www.open-std.org/jtc1/sc22/wg21/
by jcranmer 1y ago
> * uniform function call syntax that is : a.foo(b) vs foo(a, b) being interchangeable.
Herb Sutter has proposed this: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p3021r0.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p30... (twice, even, there was an older version of the paper several years ago that didn't pass).
I'm resolutely opposed to such a thing because, having had to actually wade through C++'s name lookup and overload resolution rules in the past, they're a dense, confusing morass of logic that you can only stand to stare at for a half-hour or so before your brain turns to mush and you need to do something else, and anything that adds to that complexity--especially in "this makes things two things nearly equivalent"--is just a bad idea.
(For an example of C++ overload resolution insanity, consider this:)
// Given these overloads...
void f(std::float32_t);
void f(double);
// Which one does this line call? Assume float/double are standard IEEE-754 types.
void f((float)1);
- billforsternz 1y agoI'm going to guess f(double) because floats have always been promoted to doubles for function calls since K&R. But I'm not sure by any means. I'd be ready to get more explicit if I needed some specific behaviour.
- tredre3 1y agoBy mentioning K&R you seem to imply that C also promotes floats to doubles in function calls? But that is not the case, floats are passed as floats, as you'd expect. You can try it yourself on godbolt all the way back to GCC 3, test(float x) has always emitted movss and test(double x) will result in movsd/movlpd.
- jcranmer 1y agoUnless you're calling a variable-argument function--floats are promoted to doubles for variable-argument functions: > The arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters, taking the type of each parameter to be the unqualified version of its declared type. The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter, if present. The integer promotions are performed on each trailing argument, and trailing arguments that have type float are promoted to double. These are called the default argument promotions. No other conversions are performed implicitly
- DSMan195276 1y agoIt's a difference of whether the function arguments are declared or not. If you declare a `void foo()`, and then call `foo((float)f)`, the `foo()` function is actually passed a `double` as the first argument rather than a `float`. If you instead change the declaration to `void foo(float)` then it gets passed as a `float`. Ex: https://godbolt.org/z/TKjz3Tqqr https://godbolt.org/z/TKjz3Tqqr
- billforsternz 1y agoA misconception on my part, apologies. I had somehow conflated the automatic conversion from float to double that occurs in some circumstances to something that occurs in all circumstances. Or perhaps taken a quirk from a 1980s compiler (Turbo C maybe?) to be standard behaviour. Or something like that.
- deleted 1y ago[deleted]
- Sharlin 1y agoI think there have been proposals to add universal call syntax since before C++98, some of them by Stroustrup himself.
- jjmarr 1y agoI don't want implicit conversion to float32_t. The type was introduced because of how annoying implicit conversions are.