LWN.net Logo

Well, it's quite simple, really...

Well, it's quite simple, really...

Posted Jan 18, 2011 12:08 UTC (Tue) by dwmw2 (subscriber, #2063)
In reply to: Well, it's quite simple, really... by khim
Parent article: Sobotka: Why GIMP is inadequate

"Well, this is strawman argument: of course you can just ignore all C++ extensions and then produce the same code in C++ as in C."
Can I? In the kernel we make heavy use of C99 structure initialisation. Where structures can so often change and gain new members, it's very important to have named initialisers. But this code will fail if compiled as C++:
struct foo {
	int a;
	int oh_we_introduced_this_optional_thing_later;
	int b;
};

struct foo f = {
	.a = 1,
	.b = 2,
};
Losing that facility would introduce a lot of errors into the kernel, at a single fell stroke.


(Log in to post comments)

Well, it's quite simple, really...

Posted Jan 18, 2011 13:27 UTC (Tue) by foom (subscriber, #14868) [Link]

Surprisingly, it didn't even make it into C++0x.

It seems to me it'd be a reasonable extension for "gnu++0x", though.

Well, it's quite simple, really...

Posted Jan 18, 2011 18:57 UTC (Tue) by daniel (subscriber, #3181) [Link]

The lack of designated initializers in C++ is pure brain damage. I do not understand why the issue does not get more attention. That said, the old gnu syntax still works: {foo: x, bar: y} except that you have to specify the initializers in the order declared and insert nulls if you skip fields, the latter requirement serving no imaginable purpose whatsoever. But at least in this way you can protect yourself from structure field evolution. This C advantage in no way makes up for all the structuring primitives that C lacks.

Well, it's quite simple, really...

Posted Jan 18, 2011 21:07 UTC (Tue) by foom (subscriber, #14868) [Link]

It doesn't sound like brain damage, but rather a brand new (well, 12 years old now, but by C standards, brand new) feature in C that has not been ported to C++ yet. C++ adds all sorts of additional complex interactions to such a feature that would have to be properly specified...and nobody's done that yet. You could probably get a proposal accepted for C++20 (or whatever) though...

The restrictions on the GCC extension seem like someone just didn't really finish implementing it yet. I'd bet you would be welcome to do so.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds