lua-users home
lua-l archive

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


Anyone compiling the lib as C++ is making a mistake.  C++ name mangling is
not portable, so if they ever switched compilers they would have to
re-compile the LUA libs just to be able to re-link.  If it were a C lib, and
correctly used the #ifdef __cplusplus, it would work accross all compilers
(on the same platform).
And this is what almost all other libs do (Png, Zip, FreeType, etc...)

However, I can see that this won't change the minds of the people who
matter, so I therefore endorse this guys suggestion, or something else
similar like:

#if defined(_cplusplus) && !defined(LUA_CPP)
extern "C" {
#endif

So the few people who NEED it to be C++ can define LUA_CPP

But, whatever the solution, Joe Programmer should not have to modify the
source code to make it compile.  Libs like this should work out of the box.

Brian

----- Original Message ----- 
From: "Jamie Webb" <j@jmawebb.cjb.net>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Sunday, September 14, 2003 3:53 PM
Subject: Re: extern "C" ?


> On Sunday 14 September 2003 18:06, Philip D. Bober wrote:
> > But if that were in the original files, it wouldn't affect C users
(because
> > of the #ifdef __cplusplus), only C++ users.
>
> You're missing the point: we might want to compile Lua using the C++
compiler.
> You then don't want the externs despite being a C++ user. It's only if you
> compile Lua using a C compiler (or use prebuilt library) and your program
> using a C++ compiler that you need them.
>
> A suggestion: how about using a different macro, e.g. #ifdef
LUA_EXTERN_C...,
> then people who want the externs can add that their makefiles once and
leave
> the sources alone, and people who don't want the externs won't get them.
>
>  -- Jamie Webb
>
> How to hack a Computer: Step 1: Take axe and...
>