Hacker News new | ask | show | jobs
by wsmith 3501 days 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.

2 comments

I 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)

Why 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.
C++ 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.
int new = old + 5;

:)

Oh, 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.
For 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."
That'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++

It'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.

C++'s template system is more of a dynamically typed Haskell.
This video (from the amazing Bartosz Milewski) does a great job of illustrating this:

https://vimeo.com/7211030

Learning Haskell will actually help you to understand C++ templates much better.