Hacker News new | past | comments | ask | show | jobs | submit login

There’s a lot of new things in C since the K&R book came out.



Half of them cribbed from C++.


Not really; C has a number of things that C++ never adopted such as restrict and partial structure initialization (although this might be coming to C++).


Half does mean some are, some aren't.

"//" comments, function prototypes, const, atomic, inline, complex, mid-block definitions are.

Runtime variable local arrays, designated initializers, restrict not. C++ cribbed designated initializers from C, coming in '20. Restrict was cribbed, late, from Fortran.


> C++ cribbed designated initializers from C

AFAIU C++ will require that you initialize the members in the same order as defined. It also won't permit you to exclude any definitions. Why even bother?

Somewhat controversially, C permits you to define members multiple times, with the last definition taking precedence. Compilers sometimes warn about this, but I've personally found the behavior useful--I'll write an API that provides a macro with default values yet which allows the user to override any particular definition. I don't think I've ever had a bug in an initialization, at least not involving multiple definitions. That seems like a very easy and superficially useful diagnostic to write, but which prevents useful behaviors; behaviors that named initializer's were deliberately designed to provide.


In a C++ designated initialization, members may be omitted. (You were told wrong.)

There is probably no reason to enforce order unless unmentioned elements have a non-trivial destructor, so that could be relaxed in a future Standard. Members that need destruction would need to be destroyed in the opposite order; enforcing order allows reusing code already generated for the containing-object destructor, but in many interesting cases (e.g. C structs) there are no destructors to run anyway. In the others, there is no reason why it would need to re-use the class destructor.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: