lua-users home
lua-l archive

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



On Sep 29, 2004, at 16:09, Benno wrote:

On Wed Sep 29, 2004 at 14:40:02 +0100, David Jones wrote:

On Sep 29, 2004, at 12:41, Daniel Walker wrote:

Unfortunately I can't really accept that solution as the
necessity for it is the exact problem I wished to address.
Furthermore, you may notice that

#ifndef LUA_API
#ifdef __cplusplus
#define LUA_API extern "C"
#else
#define LUA_API extern
#endif
#endif

is perfectly valid C code, which completely eliminates the
need for any C++ specifics, and would keep the issue in
question from ever arising again. There really isn't any
benefit in not writing a header like this, so why not?

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 that
code.  Only the language C++ assigns a meaning to __cplusplus, the
language C makes no guarantees.  It is only when you use a cooperating
C implementation that __cplusplus will have the meaning you like.  In
other words a C implementation is at perfect liberty to define the
token __cplusplus for its own purposes.

Incorrect. A C99 implementation is not allowed to define that macro.

Section 6.10.8.5:

"""
The implementation shall not define the macro __cplusplus, nor shall it
define it in any standard header.
"""

Benno (who doesn't know about C89)

Thanks for that, I'm certainly much more familiar with the 1989 version of the standard than the 1999 version. I stand corrected.

However, it was Rob Kendrick that pointed out the true reason: You can compile the Lua source as C or as C++. If you compile it as C++ then you want C++ linkage (not C linkage) when you include the header files so inserting the << extern "C" >> would be wrong. Arguably people who distribute binaries where Lu has been compiled as C should make the change to the header files (or include a parallel set of header files).

David Jones