News for hackers. Stuff that matters.
Re:Rust vs. C++ Formatting by Kranar on Monday January 16, 2023 @04:01PM (#34405418)
Boost had a type-safe printf function dating back to October 10th, 2002:

https://www.boost.org/doc/libs/1_31_0/libs/format/

Re:Rust vs. C++ Formatting by 1ris on Monday January 16, 2023 @04:27PM (#34405707)
And outstreams where not that bad, aswell. Sure, the operator overloading looks a bit rough. But that's IMHO a pragmatic choice if you want to offer customisation points and didn't have variadic functions yet. They where introduced only in c++11.
Re:Rust vs. C++ Formatting by tialaramex on Monday January 16, 2023 @04:34PM (#34405785)
C++ did have variadic functions because it inherited them from C.

What it didn't inherit from C was a way to write variadic functions with variadic types, so that had to be home grown.

Re:Rust vs. C++ Formatting by 1ris on Monday January 16, 2023 @04:50PM (#34405941)
Do you mean this feature [0]? I'm not aware of any differences in c and c++ about this. Can you get a type of a argument in C? How? At compile time, or at runtime? Both sound very un-C-like to me. cppreference is usually excellent documentation but it doesn't mention something like this.

I don't considers this to be "proper" variadic arguments, because a functions argument has to have a type. and these, as far as I'm aware of don't have one. This is about a powerfull as passing a void**. This is essentially memcopying multiple differently typed into a char* buffer and then passing that buffer. You can than correctly copies them back you have pretty much the same behaviour. Both methodss obviously lacks important aspects of the language abstraction of a function parameter and i don't what that feature can bring to the table that the previous techniques don't.

[0] https://en.cppreference.com/w/cpp/utility/variadic

Re:Rust vs. C++ Formatting by kevin_thibedeau on Monday January 16, 2023 @05:08PM (#34406098)
> Can you get a type of a argument in C?

You can get it indirectly using _Generic().

Re:Rust vs. C++ Formatting by 1ris on Monday January 16, 2023 @06:06PM (#34406742)
Sorry my bad. Yes, it works for proper function arguments. Does this work for variadic arguments? Parent seems to suggest, but i'm not aware of any mechanism for this.