News for hackers. Stuff that matters.
Re:I love coding in C by rumanator on Thursday December 26, 2019 @10:43AM (#21884541)
> Coding in C is like camping. It's fun for a while, but eventually you really miss things like flushing toilets and grocery stores.

The only issue I have with C is that there are no good reasons for some of those missing features to be missing.

Take, for example, namespaces. Would it be a problem to implement them as, say, implicit prefixes?

Re:I love coding in C by Gibbon1 on Thursday December 26, 2019 @02:51PM (#21886212)
That's exactly my complaint. I think it's missing things because if you added them in a way compatible with the C way of doing things then you would permanently cleave C from C++. Since C++ is a runaway train at this point detaching is probably a good idea now.

Me I want range types like Ada. Real array types. I think I want blocks/coroutines.

Re:I love coding in C by agumonkey on Thursday December 26, 2019 @03:38PM (#21886561)
> Me I want range types like Ada. Real array types. I think I want blocks/coroutines.

aka CDC

Re:I love coding in C by AllanHoustonSt on Thursday December 26, 2019 @10:48AM (#21884571)
Would it be possible to do this without changing how name mangling works?
Re:I love coding in C by a1369209993 on Thursday December 26, 2019 @02:14PM (#21885956)
Actually, 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" */
Re:I love coding in C by frabert on Thursday December 26, 2019 @10:52AM (#21884598)
There's no name mangling in C, at least not in any ABI I know of.
Re:I love coding in C by saagarjha on Thursday December 26, 2019 @11:04AM (#21884682)
There’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.
Re:I love coding in C by rumanator on Thursday December 26, 2019 @12:07PM (#21885131)
> 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.

Re:I love coding in C by john111 on Thursday December 26, 2019 @01:08PM (#21885553)
What'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?

Re:I love coding in C by rumanator on Thursday December 26, 2019 @01:20PM (#21885600)
> 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

Re:I love coding in C by einpoklum on Friday December 27, 2019 @05:35AM (#21890469)
> What's the point?

using namespace kind::ofa::long_name;

or

using kind::ofa::long_name::bar;

is the point.

Re:I love coding in C by weberc2 on Thursday December 26, 2019 @11:22AM (#21884823)
As 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.
Re:I love coding in C by maxxk on Thursday December 26, 2019 @01:43PM (#21885760)
And 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.
Re:I love coding in C by MiroF on Thursday December 26, 2019 @11:14AM (#21884762)
Or something like the std::vector would be nice.
Re:I love coding in C by Impossible on Thursday December 26, 2019 @12:12PM (#21885165)
https://github.com/nothings/stb/blob/master/stretchy_buffer.... Although I get you want an official standard library version, or a built in language feature.
Re:I love coding in C by Koshkin on Thursday December 26, 2019 @01:42PM (#21885755)
I think GP’s point was that what you want is called “C++”.