[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua.h and c++
- From: David Jones <drj@...>
- Date: Wed, 29 Sep 2004 14:40:02 +0100
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.
Adding C++ code to the standard Lua distribution would require the
maintainers to maintain the C++ code as well. I'm sure they don't want
to do that.
The standard way for a C++ program to include a C header file is to go:
extern "C" {
#include "c-header.h"
}
why is it that C++ programmers seem so squeamish about doing this?
Basically, I approve of the Lua maintainers' current position.
David Jones