Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 May 2009 10:00:32 -0700
From:      "Matthew Fleming" <matthew.fleming@isilon.com>
To:        "Bakul Shah" <bakul@bitblocks.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   RE: C++ incompatability, was C99: Suggestions for style(9) 
Message-ID:  <06D5F9F6F655AD4C92E28B662F7F853E02ACA852@seaxch09.desktop.isilon.com>
In-Reply-To: <20090501163108.576465B3B@mail.bitblocks.com>
References:  <49F4070C.2000108@gmx.de><20090428114754.GB89235@server.vk2pj.dyndns.org> <49FAE4EA.1010205@gmx.de> <06D5F9F6F655AD4C92E28B662F7F853E02ACA843@seaxch09.desktop.isilon.com> <20090501163108.576465B3B@mail.bitblocks.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> > [snip exciting discussion on style]
> >=20
> > > There are several C99 features used already, e.g. designated
initializers:
> > >	bla bli =3D { .blub =3D "foo", .arr[0] =3D 42 };
> > > Do you suggest that this should not be used, because it is
inconsistent
> > > with all the other existing compound initialisations?
> >=20
> > Regarding this great feature of C99, sadly, it's not C++ compatible.
So
> > while designated initializers in a C source file are great, in a
header
> > file they will give a compile error if included in e.g. a C++ kernel
> > module (which otherwise would work fine).
>=20
> Why would you put initializers in a header file? If included
> in more than one file, the linker will complain that the
> initialized variable is multiply defined.  If creating header
> files that get included in in only one file *and* you want to
> use initializers, why not use the right language for include
> file code.

Macros, like MALLOC_DEFINE, DB_COMMAND, etc., define initialized
variables when used.  These can't be changed to use named initializers
without breaking C++.

Thanks,
matthew



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?06D5F9F6F655AD4C92E28B662F7F853E02ACA852>