They are in discussions to introduce the following in C:
* nullptr
* auto
* __has_include
* make false and true first-class language features
* constexpr
and lots of other goodies [1].They are in discussions to introduce the following in C:
* nullptr
* auto
* __has_include
* make false and true first-class language features
* constexpr
and lots of other goodies [1].Now thats exciting
If C could fix _Generic from C11 and make it behave more like a lightweight version of templates, then I could say we have a huge potential of having a safer version of what we currently have.
As a C programmer, aren't classes, templates, and exceptions the things that have classically differentiated C and C++?[0] I don't see anything obviously objectionable about nullptr[1], auto, __has_include, or constexpr. (I don't have a ton of experience with them, either.)
I'll admit I don't really grok what "make false and true first-class language features" means — maybe make them reserved keywords? (int)true must still evaluate to 1, in any event.
[0]: "C++ is C with classes!"
[1]: C's "NULL" has this obnoxious wart in that it is implementation-defined whether or not it is a pointer type. I.e., it can be "(void *)0" or just "0". This means that it cannot be used safely in portable incantations of variadic functions that expect pointer arguments.
We're going to have to agree to disagree on that one.
> It's like C is slowly realizing C++ features are actually useful, but doing so as slowly as molasses, while still trying to pretend like this isn't the case...
I think it makes sense to adopt C++ features that do some combination of (1) providing a useful feature, (2) aiding C++ compatibility, and (3) not majorly increasing the conceptual size of the C language. Just like it makes sense for C++ to adopt C99-compatibility (structure literals has taken y'all like 20+ years to adopt).
Templates, classes, and exceptions are a huge huge addition to the complexity of the language. If C programmers wanted them, with all of the pitfalls of manual memory management and C-style lifetime safety, they'd just use C++. Obviously, they don't.
Personally, if I had to choose a language other than C I'd pick something like Zig, Rust, or Go over C++.
Why only variadic functions? The answer to that may make my next question obsolete, namely: Wouldn't only C++ complain about this? In C, isn't the input to anything coerced to the data type it will represent, in actual complete disregard of the input type?
For variadic functions, the compiler doesn't know the parameter type.
So to print a null pointer, you need to do this:
printf("NULL = %p\n", (void*)NULL);
or printf("null pointer = %p\n", (void*)0);
The %p format requires an argument of type void*, so you have to convert to that type if necessary.This works:
void f(char *p);
f(0); /* integer literal auto promoted to pointer */
This probably doesn't, at least not as the number of arguments to f is increased: void f(...);
f(0); /* assume type of function is void f(int) */For non-variadic functions, the function declaration provides the correct parameter type, and caller arguments are coerced to the correct type.
> In C, isn't the input to anything coerced to the data type it will represent, in actual complete disregard of the input type?
In short: no. Implicit casts between incompatible types are warnings/errors.
The key difference is the destructor. Classes, templates, and exceptions extend the reach and value of the destructor. Absent the destructor, the other stuff is of little value (cf. Java).