I actually came across this problem when compiling Lua, and the only pertinent
Google result I found was on the Lua mailing list:
http://lua-users.org/lists/lua-l/2006-09/msg00196.html. Specifically, I
was compiling {LuaRoot}/etc/all.c, if you need to reproduce the entire problem.
As a minimal example:
/*** begin example ***/
#include <stdio.h>
const char *const foo []; /* <-- problem line here */
const char *const foo [] = { "one", "two",
"three" } ;
int main()
{
int i;
for (i = 0 ; i < 3 ; i++)
{
printf("%s\n", foo[i]);
}
return 0;
}
/*** end example ***/
GCC compiles this with no warnings or errors. TCC gives me the error
"fail.c:3: unknown type size". If I comment out the forward
declaration, it works fine (not that you need it in this small of an example
anyway). If I explicitly declare the size of the array (3, of course), it
compiles and runs fine. It also works fine if I forward declare foo as an
extern array without an indicated size. I've tried TCC versoin 0.9.24
on Ubuntu, and TCC version 0.9.25 through Wine on Ubuntu, both with the same
results.
Section 8.3 of the TCC documentation does say that TCC does one pass, except
"For initialized arrays with unknown size, a first pass is done to count
the number of elements." I understand that fewer passes is what
keeps TCC so much faster than the competition, but I guess I don't know
enough about compilers to infer whether that forward declaration *should* be
enough to cover in a single pass.
Lua does claim that it "is implemented in pure ANSI C and compiles
unmodified in all platforms that have an ANSI C compiler." For what
it's worth, using the Makefile, Lua compiles fine under TCC, but it's
only when I try to compile all.c (which basically #include's everything
into one flat file, does not use a makefile) that the problem arises.
The first offending line is
LUAI_DATA const char * const luaT_typenames[];
where LUAI_DATA is just defined as empty when compiling with all.c, otherwise
LUAI_DATA is defined to be extern (which is why the Makefile approach works,
apparently).
So, is this a bug on Lua's side (incorrectly defining LUAI_DATA) or is this
a bug on TCC's side?
<img src="http://www.bigstring.com/refer.php?img=68" width="1" height="1">Start
making money with PeopleString!
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel