[Neko] Neko 1.1 Release: building under C++
skaller at users.sourceforge.net
Thu Nov 10 17:48:30 CET 2005
On Thu, 2005-11-10 at 22:26 +0900, Nicolas Cannasse wrote:
> skaller wrote:
> Just edit the Makefile and enable the 64 bit compilation mode.
> CFLAGS += -D_64BITS
Done, now it works. However I have made another change now:
to the Makefile I add:
because I want to compile the code as C++ not C. And I get:
vm/neko.h:281: error: expected ‘,’ or ‘...’ before ‘this’
because Neko is using 'this' as an identifier, but in
C++ it is a keyword. Fixed that, then got this:
vm/alloc.c:43: error: redefinition of ‘_value* val_null’
vm/neko.h:251: error: ‘_value* val_null’ previously declared here
EXTERN value val_null = (value)&t_null;
EXTERN value val_null;
The latter code is wrapped in extern "C" using C_FUNCTION_BEGIN.
Also EXTERN is #defined as nothing.
I think this is wrong in C++, and suspicious in C.
To declare, but not define, a variable, you MUST use 'extern',
and to define it .. you must not ;(
I changed IMPORT to be 'extern' and got a different error:
vm/alloc.c:43: warning: ‘val_null’ initialized and declared ‘extern’
The problem is that, in alloc.c, val_null is ALWAYS an EXPORT.
You cannot import a symbol you're defining. So I changed it to:
EXPORT value val_null = (value)&t_null;
in vm/alloc.c and the problem went away. So I think this is
a bug .. even though it works in C :)
The general rule, I think, is: in a *.c file, everything
should either be static, or EXPORT, never EXTERN.
EXTERN is only needed in header files, where it must
map to EXPORT when you're compiling and linking the
library involved, and IMPORT when you're using it
from the mainline or other library (to get the declspec
stuff right on Windows).
Another problem is this:
vm/alloc.c:80: error: invalid conversion from ‘void*’ to ‘char*’
which is easily fixed by just adding an explicit cast.
C allows void* to cast to anything implicitly, C++ does not.
vm/alloc.c:243: error: invalid conversion from ‘void (*)(_value*)’ to
vm/alloc.c:243: error: initializing argument 3 of ‘void
GC_register_finalizer(void*, void (*)(void*, void*), void*, void
(**)(void*, void*), void**)’
[This is not allowed in C++ even WITH a cast.. but it works
on most compilers because there is no alternative. I am partly
responsible for this rule. I am not responsible for failing
to provide a generic function pointer type fun_type_t .. :]
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
More information about the Neko