5 ms·
C for all: Parametric polymorphism in C
- anon3_ 11y agoWe're reaping the benefits of C's resistance to feature bloat. C powers the daemons and operating systems of the world. When you're working in the field, C's transparency and absence of esoteric programming voodoo is a feature, not deficit. Interest posting made today similar: https://news.ycombinator.com/item?id=9827051 https://news.ycombinator.com/item?id=9827051
- the_why_of_y 11y agoHow does "undefined behavior" not qualify as "esoteric programming voodoo"?
- xamuel 11y agoUB is not something that a competent programmer does intentionally. You shouldn't ever run into a situation where you'd tell your fellow programmer, "Hey, on line 300 here, you're doing UB, stop it", only for them to say "No, I'll do UB if I please". With C++ on the other hand, you could very well run into situations where you plead with your fellow programmer, e.g., "please stop overloading operators in this opaque and unmaintainable way", and then they tell you, "so what, that's our in-house style and it has official language blessing".
- pjmlp 11y agoSadly I am yet to work in an enterprise environment that fully understands the meaning of "competent programmer" in their hiring process, specially for offshore resources.
- the_why_of_y 11y agoC++ has roughly the same undefined behaviors as C, plus a bunch of additional ones for the C++ specific features. Also, you'd be surprised how many stubborn C programmers apparently think that mutable global variables are an excellent and convenient time-saver. (Not that C++ programmers do inherently any better here, cf. Singleton)
- cwzwarich 11y agoThe C spec also has a handy appendix listing all undefined behavior, which IIRC the C++ spec does not have.
- epsylon 11y agoYet even the most competent programmers will have UBs crawl into their code where they do not expect them. Sure, C has less pitfalls than C++ ; but it has its own as well. (see previous discussion on HN "What is C", John Regehr's blog, ...)
- wcummings 11y agoIn the field?
- huhtenberg 11y agoThis has no chances of going mainstream, but this is a thoughtful and careful exploration of a C extension. Type system [1] is nicely done (though I think it looks a bit clunky in application). Tangentially related - once you worked with C long enough, the lack of of "templates" becomes pretty obvious. If you need two functions that do the same thing for two different input types, you have two options - wrap it into a multiline define or use one generic function and use a callback to deal with type differences, a'la qsort(). Neither is exactly ideal. Does anyone know of C dialects with some form of template support? [1] http://plg.uwaterloo.ca/~cforall/typesystem.html http://plg.uwaterloo.ca/~cforall/typesystem.html
- Rexxar 11y ago> Does anyone know of C dialects with some form of template support? C++, but I'm sure it's not the answer you want. It would be nice if C++ compilers had more fine grained switch to activate only functionality people want to use. It would be better, IMHO, than creating a new incompatible language each time. A "C + template" would be useful for many people who don't want the full C++.
- Qantourisc 11y agoHow does the extra functionality impact the final binary ? Or do the compilers add extra things you don't need even if you don't use them ?
- m_mueller 11y agoC lang has certain features that C++ doesn't. Most notably the "restrict" keyword to make the compiler aware that you don't intend to alias a pointer. AFAIK there is no portable way to do this in C++. This is relatively important feature in HPC. So yeah, I'd very much support the idea of "C plus templates", at least in my field this would get a lot of usage.
- Narishma 11y agoThe feature may not be in the C++ standard but the main compilers support it anyway (__restrict__ in GCC and Clang, __restrict in MSVC).
- pavlov 11y agoThis is almost 20 years old, isn't it? The text refers to a C9x standard, so it must predate the standardization of C99.
- kazinator 11y ago> Structure Prototypes: This was proposed in February 1998 in comp.std.c by bill@cafe.net (Kaz Kylheku). The idea is that eliding member names in a structure prevents access to the members. Hey, thanks for the credit.
- deleted 11y ago[deleted]
- agumonkey 11y agoJust when I was looking for C-with-tuple-and-destruct. Brilliant.
- filereaper 11y agoPeter Buhr also teaches CS343: Concurrent and Parallel Programming. CS343 uses uC++ which has coroutines, threads, monitors and other constructs used to teach advanced control flow. [0] http://plg.uwaterloo.ca/~usystem/uC++.html http://plg.uwaterloo.ca/~usystem/uC++.html [1] https://www.student.cs.uwaterloo.ca/~cs343/ https://www.student.cs.uwaterloo.ca/~cs343/ [2] http://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++book.pdf http://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++book.pdf