Cello icon indicating copy to clipboard operation
Cello copied to clipboard

Does not compile with tcc 0.9.27

Open evolbug opened this issue 8 years ago • 8 comments

Cannot compile either v2.0.3 and v2.1.0 with the latest tcc version from http://repo.or.cz/tinycc.git mob branch.

tcc src/Table.c -c -I ./include -std=gnu99 -Wall -Wno-unused -g -ggdb -fdollars-in-identifiers -fPIC -DCELLO_NSTRACE -o obj/Table.o
src/Table.c:156: error: cannot cast 'struct Tuple' to 'void **'
make: *** [Makefile:125: obj/Table.o] Error 1

However, this page http://libcello.org/learn/best-improvements-of-cello-2.0 under Portability mentions that it can indeed be done

[..] Cello can be compiled easily with all of the major compilers including gcc, clang, cl.exe, and tcc (on the development branch).

Has anything changed since or has tcc not been tested?

evolbug avatar May 24 '17 13:05 evolbug

Just not tested recently. I guess some aspect of tcc has changed. It isn't immediately obvious why tcc is throwing that error so I'll have to dig a little deeper to see exactly what is going on.

orangeduck avatar May 25 '17 00:05 orangeduck

Would love to see this fixed. I am creating a project that needs to bundle TCC and use Cello. I don't want to have to rely on the system compiler for each platform.

Attempted hello world example using TCC and failed:

tcc -fdollars-in-identifiers -I. example.c -L. -lCello -DCELLO_NSTRACE
#define CELLO_NSTRACE
#include "Cello.h"

int main(int argc, char** argv)
{
	print("ASDF\n");
	return 0;
}

Compiles with GCC just fine but throws this error when used with TCC:

example.c:6: error: cannot cast 'struct Tuple' to 'void **'

I could be wrong, but I believe it is referring to the string being passed to the print function inside the tuple of arguments.

Also, just discovered this project and I think it is amazing! Keep up the good work!

Pebaz avatar Jan 04 '19 14:01 Pebaz

Thanks I'll try to find some time to work out what has changed. Looks like it might be something in the macros used for variable argument functions...

orangeduck avatar Jan 05 '19 21:01 orangeduck

Have you had a chance to look into this? =)

Pebaz avatar Jan 12 '19 23:01 Pebaz

I took a look. For some reason tcc is expanding macro arguments not really as expected. For example if I do:

var x = new(String);

Then it will throw that error, however if I do this:

var x = new_with(String, tuple());

It works fine...

However the definition of new is pretty much exactly that:

#define new(T, ...) ((struct T*)new_with(T, tuple(__VA_ARGS__)))

Even if you remove all the other stuff you still get the same error:

#define new(T, ...) new_with(T, tuple(__VA_ARGS__))

It seems to be failing to expand tuple(__VA_ARGS__) properly into tuple() when no arguments are passed to these variable argument macros.

Here I am not sure exactly what to do - I tried all my normal preprocessor hacks to try and get it to expand differently but I couldn't find anything that works. Maybe it is worth reporting a bug with tcc and/or to try and dig into the source code to try and fix it?

Either way I have a feeling this is not Cello related and the same issue might exist in normal C programs compiled with tcc. I hope that helps!

Dan

orangeduck avatar Jan 16 '19 02:01 orangeduck

Thank you very much for taking time out of your day to address this. I really appreciate it! Although the new() macro is nice, I will work with new_with() using an empty tuple for now until I can address this issue with TCC.

Thank you for narrowing this down and for creating such an ingenious project!

Pebaz avatar Jan 16 '19 14:01 Pebaz