This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Buggish behaviour of nested unnamed struct in extern "C" clause?

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]