This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Buggish behaviour of nested unnamed struct in extern "C" clause?
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: "David Lucena" <yakumoklesk at yahoo dot es>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 28 Nov 2007 04:26:26 -0800
- Subject: RE: Buggish behaviour of nested unnamed struct in extern "C" clause?
- References: <437063.68584.qm@web54003.mail.re2.yahoo.com>
Hi David,
> What I am missing?
Program in C, not in C-with-Microsoft-extensions.
For interoperability between C and C++ for code and headers written in C, program in portable C.
Portable C avoids all non-portable C-isms, C/C++ incompatibilities, and non-portable extensions. Portable C -- which is a coding convention / discipline -- also makes sure the headers have the extern "C" wrappers for C++, making them C++ savvy.
Your use of unnamed structs data members does not comply with portable C, as it is considered a scoped forward declaration in C++ rather than a data member.
To aid in writing portable C, enable all compiler warnings that you can.
To aid in writing C / C++ interoperability, test-compiler your headers with the C++ compiler with all the warnings enabled to help you catch any C++ problems in your header files. Just putting in the extern "C" scope isn't enough, as there are some nuanced differences between C and C++.
For information on portable C, use Google for "writing portable C". You may find hits on "Portable C Compiler" ... that's something else.
HTH,
--Eljay