lua-users home
lua-l archive

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


> 3) More severe, but in a quite special configuration.
> It seems impossible to compile the amalgamation in C++.
> I try to use the one.c file from Luiz. It works fine in C mode. When
> trying in C++ mode, you have several errors like:
>   lobject.h:581:24: error: uninitialized const 'luaO_nilobject_'
> both on GCC than on Visual Studio.

This seems to indicate a difference in the way C++ and C handle 'static'
declarations. The problem seems to be constructions like this:

static int i;
...
static int i = 0;

I am not very sure even about C. I do not have the C89 standard,
but [1] apparently says that such double declarations is not valid
C. On page 75, it says that any static declaration of a variable is a
"defining declaration". On page 71, it suggests that such variables
should be declared extern, even if they are not used elsewhere.

The C99 standard, on the other hand, says that

  A declaration of an identifier for an object that has file scope without
  an initializer, and without a storage-class specifier or with the
  storage-class specifier static, constitutes a tentative definition.

So, the above construction should be OK.


[1] C: A Reference Manual (4th edition). Haribson & Steele, 1995.

-- Roberto