This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] warning about empty extern "C" structures
On Wed, 2006-05-17 at 11:45 -0500, Roman Kononov wrote:
> On 05/17/2006 11:12, Gabriel Dos Reis wrote:
> > | They prevent from introducing safe C++ code.
> >
> Header.h and driver.c are old GCC code using all possible GCC extensions.
> User.cpp is an attempt for C++ to co-exist in the Linux kernel. To make
> driver.c and user.cpp, linked together, to work as they should, one needs to
> do something with extern "C" struct spinlock_t {};. Currently, there is no
> compiler help for the user compiling his user.cpp file to know about such
> misbehavior.
What I do not understand is why g++ assumes a C++ layout for the
device_t (or spinlock_t) structure. extern "C" is supposedly meaning
using the C layout whatever it is, no ?
Of course, then it is the use of such empty structures in g++ as members
or bases that should be forbidden, and should trigger an error...
The current behaviour is a kind of a lie (unless I have skipped
something in the C++ standard that explicitely allows for this
interpretation) and error prone. Then of course, it is only a gnu C
extension (but maybe a commonly used one).
The other real alternative would be to have empty struct to behave in C
as they do in C++, and I guess that many people would hate that...
Theo.