lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Wednesday, September 29, 2004 9:40 AM David Jones said:

> That code is conforming C code, but not strictly conforming C code.  
> Since it uses a pre-processor token ("__cplusplus") that is in the 
> namespace reserved for the implementation, then any given C 
> implementation is allowed to assigned whatever meaning it likes to
> code.  

I believe that is technically untrue --

ISO/IEC 9899:1999 (the C99 specification) states that "The
implementation shall not predefine the macro __cplusplus, nor shall it
define it in any standard header." (section 6.10.8)

ISO/IEC 14882:1998 (the C++98 specification) states that "The following
macro names shall be defined by the implementation: ... __cplusplus."
(section 16.8)

So, a standard-conforming compiler will always "do the right thing" when
it comes to __cplusplus. I do agree that not all compilers are
compliant, and trying to #define __cplusplus yourself will usually lead
to undefined behavior -- which, in my view, is why we have (and should
take advantage of) standards in the first place!

> The standard way for a C++ program to include a C header file is to
> extern "C" {
> #include "c-header.h"
> }
> why is it that C++ programmers seem so squeamish about doing this?

It is because we are lazy :). It is easier to #include "c-header.h"
wherever we need it than it is to remember which headers need extern "C"
around them and which do not.

I hope I did not contribute to the C vs. C++ wars here :)