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
- From: Daniel Jacobowitz <drow at false dot org>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Roman Kononov <kononov195-far at yahoo dot com>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 17 May 2006 11:29:59 -0400
- Subject: Re: [C++ PATCH] warning about empty extern "C" structures
- References: <e4fce1$nrb$1@sea.gmane.org> <m3lkt04r4l.fsf@uniton.integrable-solutions.net>
On Wed, May 17, 2006 at 05:18:02PM +0200, Gabriel Dos Reis wrote:
> Roman Kononov <kononov195-far@yahoo.com> writes:
>
> | This patch adds an option for g++ to emit a warning when it sees
> | extern "C" { struct foo {}; }
> | Such empty structures have different sizes in C++ and C modules. Linked
> | together the modules make the life painful. Supplying -Wempty-c-struct
> | option tells g++ to warn. Default is not to warn.
>
> I don't understand this.
>
> [ I understand that empty structs are invalid in C. ]
But not in GNU C:
GCC permits a C structure to have no members:
struct empty {
};
The structure will have size zero. In C++, empty structures are part
of the language. G++ treats empty structures as if they had a single
member of type `char'.
It's exactly that distinction that this patch would warn about; I think
it's a good idea, and I'd even suggest warning about it in -Wall
(maybe not in system headers?)
--
Daniel Jacobowitz
CodeSourcery