7 ms·
Would it be possible to do this without changing how name mangling works?
by AllanHoustonSt 7y ago
Would it be possible to do this without changing how name mangling works?
- frabert 7y agoThere's no name mangling in C, at least not in any ABI I know of.
- saagarjha 7y agoThere’s “mangling” where symbols have an underscore put in from of them. But I think the point is that namespaces functions would need to be mangled and thus be difficult to call.
- weberc2 7y agoAs far as I know, name mangling only exists because linkers don’t have a notion of namespaces. If you fix linkers, then there is no need to mangle.
- maxxk 7y agoAnd also because of function overloading in, say, C++. To link code two functions with the same identifier which differ only in signature (e.g. types of arguments), we need to pass them to linker as two different functions with different identifiers.
- rumanator 7y ago> But I think the point is that namespaces functions would need to be mangled Namespaces don't need to be mangled at all if they are interpreted as symbol prefixes. I'd prefer that, say, namespace foo::bar resolved into foo_bar for all symbols (even that meant risking namespace naming collisions) to not having any support for namespaces in C. In fact, this approach is already used to implement pseudo-namespaces, so that wouldn't be much of a stretch.
- john111 7y agoWhat's the point? How is typing foo::bar better than typing foo_bar? It seems like you want the language to be more complicated for no benefit. Why not use C++ at that point?
- rumanator 7y ago> What's the point? How is typing foo::bar better than typing foo_bar? You're missing the whole point of namespaces. The goal is not to replace foo_bar with foo::bar. The whole point is that within a scope you can type bar instead of foo::bar, or bar instead of foo::baz::qux::bar, because you might have multiple identifiers that might share a name albeit they are expected to be distinct symbols. https://en.wikipedia.org/wiki/Namespace https://en.wikipedia.org/wiki/Namespace
- einpoklum 7y ago> What's the point? using namespace kind::ofa::long_name; or using kind::ofa::long_name::bar; is the point.
- a1369209993 7y agoActually, yes: #include <string.h> __prefix__ str; /* in scope: "","str" */ strlen("Hi!"); /* try "strlen",done,ignore "strstrlen" */ len("Bye"); /* no "len",try "strlen",done */ __prefix__(foo_) { void bar(void); } /* "foo_bar" */