4 ms·
> C doesn't need that because it doesn't have namespaces, generics or overloading. Overloading as in operator overloading? Because I don't see how that would a
by kibwen 9y ago
> C doesn't need that because it doesn't have namespaces, generics or overloading.
Overloading as in operator overloading? Because I don't see how that would affect symbols.
Though along with namespaces and generics, there is one thing that Rust also bakes into symbols: versioning information. This is how, in the case of deep dependency graphs, it's possible for a finished binary to include multiple copies of the same library in the event that multiple versions are transitively depended upon. But that doesn't add any complexity to symbol mangling on its own, because if you already have namespaces then you can just treat it as a namespace that only the compiler can see.
- zid 9y agoIt would need it if it had it. How do I find your code that adds bananas together using a banana adding operator via a text name?
- kibwen 9y agoIf you're referring to the ability to define entirely new symbolic operators like you can do in Haskell and Scala, then you'll be happy to hear that Rust doesn't support such a thing. (Frankly, I'm happy about it too. :P ) Rust only allows you to overload a fixed set of operators, and that overloading is all done via traits with well-known names (e.g. overloading the plus symbol "+" is done via implementing std::ops::Add for a type), and traits too can be effectively treated like namespaces as far as symbols are concerned.
- simias 9y agoNo I meant parameter-based function overloading like C++ has (or is it not the wrong term? I forget). So like: int do_something(int param); int do_something(double param, char *param2); I don't see how you can avoid some form of name mangling since obviously you can't just define two duplicate "do_something" symbols.
- steveklabnik 9y agoRust does not currently support parameter-based function overloading, and there are no plans to in the near-term, if ever. (This isn't the only way to end up with duplicate symbols, just trying to make it clear that this specifically won't be a problem with Rust.)
- Someone 9y agoNitpick: C11 introduced support for some form of that kind of overloading, using _Generic macros. See http://en.cppreference.com/w/c/language/generic http://en.cppreference.com/w/c/language/generic, https://stackoverflow.com/questions/9804371/syntax-and-sample-usage-of-generic-in-c11 https://stackoverflow.com/questions/9804371/syntax-and-sampl..., https://stackoverflow.com/questions/40096584/c11-generic-usage https://stackoverflow.com/questions/40096584/c11-generic-usa.... Ugly? Yes, IMO, but it also is useful.