tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] tcc_add_symbol with macros


From: David Mertens
Subject: Re: [Tinycc-devel] tcc_add_symbol with macros
Date: Fri, 15 Jul 2016 13:27:41 -0400

Hello Joel,

As I understand it, tcc_add_symbol only adds things that can be pointed to. In your case, gdispClear is not something that can be pointed to, it's just a macro, i.e. an instruction to the compiler on how to produce C code. Functions and global variables can be pointed to, so they are the appropriate targets for tcc_add_symbol. You should add those.

But, what exactly are you trying to accomplish? You probably want to provide the macro-exposed interface to consuming code. In that case, you could do the following one-two punch: add preprocessor definitions with tcc_define_symbol, and then add the symbol to the function itself with tcc_add_symbol. Also be sure to tcc_add_symbol GDISP. If you have to do this with a bunch of functions, you might consider wrapping that work in a script of some sort, but I leave that decision up to you. (If you work with Perl---and if you work with Cygwin then you should have Perl available---I'd be happy to figure out something, but I'd need a bit more information about the specific headers.)

David

On Thu, Jul 14, 2016 at 1:38 PM, Joel Bodenmann <address@hidden> wrote:

Hi folks,

 

I am using libtcc. So far everything is going smoothly. Now I’d like to make some “built-in” functions available to the program that is being compiled as shown with the add() function in the libtcc_test.c example. It works well with pure C functions, however, in my library that I would like to use I have functions and macros like this:

 

void gdispGClear(GDisplay* g, color_t color);

#define gdispClear(c) gdispGClear(GDISP, c)

 

void gdispGDrawPixel(GDisplay* g, coord_t x, coord_t y, color_t color);

#define gdispDrawPixel(x,y,c) gdispGDrawPixel(GDISP,x,y,c)

 

And so on… GDISP is a global variable in the file that declares those functions, something like a “default value”.

Using tcc_add_symbol() on the functions themselves (eg. gdispGClear()) works well, however, I’d like to use tcc_add_symbol() with gdispClear() instead. Sadly that doesn’t compile. I get the following error:

 

                ‘gdispClear’ undeclared (first use in this function)

 

I think that I understand why that doesn’t work. However, is there still a workaround to get this working?

 

 

Thank you for your help & best regards,

~ Joel


_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel




--
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]