6 ms·
by relaxing constrains, constant expressions became so powerful that a C compiler can be implemented in! I wonder how long it will take before C++ accidentally
by wsmith 10y ago
by relaxing constrains, constant expressions became so powerful that a C compiler can be implemented in!
I wonder how long it will take before C++ accidentally becomes a Lisp.
- gumby 10y agoI discussed this very thing with Stroustrup as far back as the mid 1990s. He was, for example, a big fan of Lisp's macro capabilities, and described templating as a way of providing this kind of capability while (back then it was a goal) the ability to compile C. (Compiling C is mostly out the window now of course)
- marssaxman 10y agoWhy do you say that compiling C is "mostly out the window"? It's difficult to imagine how C++ could change in a way that broke C compatibility without also breaking compatibility with a great deal of C++ code.
- OskarS 10y agoC++ isn't compatible C, it never was. There's lots of valid C code that isn't valid C++. For instance, this line: int *new = malloc(sizeof(int)); is valid C but invalid C++ for two different reasons: "new" is a keyword in C++, so you can't use it as an identifier, and C++ doesn't allow implicit casts from void*, while C does.
- deleted 10y ago[deleted]
- dmitrygr 10y agoint new = old + 5; :)
- marssaxman 10y agoOh, sure, and the void pointer thing, etc., but that's all been true from the start. From gumby's comment I got the impression that there might be some more recent trend toward abandoning C compilation, and that's what I have a hard time imagining.
- spc476 10y agoFor years, Microsoft's C compiler only supported C89 and would choke on C99 code (that used C99 features). That has recently changed (I'm guessing with the release of C11, which made certain C99 features optional instead of mandatory) but for a long time, it seemed that Microsoft was saying "We don't care about C."
- gumby 10y agoThat's basically what I mean: both the C++ and C committees have been OK with C++ not being a proper superset of C. The reason I mentioned it is that some of the syntactic horrors of C++ could safely be thrown out the window these days. BTW though I'm primarily still a Lisp programmer I do like C++
- munificent 10y agoIt's true that the C circle in the Venn diagram leaks out of the C++ circle a bit, but I find in practice most of it is contained quite well inside the C++ one. My current hobby project is a language VM that compiles cleanly as both C and C++. It took very little effort to get it working in C++ despite hacking on it for months as a strictly C project first.
- deleted 10y ago[deleted]
- knome 10y agoC++'s template system is more of a dynamically typed Haskell.
- RcouF1uZ4gsC 10y agoLearning Haskell will actually help you to understand C++ templates much better.
- xwvvvvwx 10y agoThis video (from the amazing Bartosz Milewski) does a great job of illustrating this: https://vimeo.com/7211030 https://vimeo.com/7211030