tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Libtcc and existing variables


From: Joel Bodenmann
Subject: Re: [Tinycc-devel] Libtcc and existing variables
Date: Fri, 29 Sep 2017 13:10:14 +0200
User-agent: Zoho Mail

Thank you a lot for your message, grischka. That worked out just fine!
Keep up the good work - thank you for keeping this project running!


Best regards,
~ Joel


-----Original Message-----
From: Tinycc-devel
[mailto:address@hidden On Behalf Of
grischka
Sent: Thursday, September 28, 2017 09:23
To: address@hidden
Subject: Re: [Tinycc-devel] Libtcc and existing variables


Joel Bodenmann wrote:
> Hello folks,
> 
>  
> 
> I am successfully using libtcc in an application. I'm very happy with 
> it and I thank you for providing this awesome tool.
> 
> So far, my needs were basically completely covered by the 
> libtcc_test.c example program that uses tcc_add_symbol() to give the 
> compiled program access to a function that exists in the host 
> application (I'm sorry if my terminology is off here). However, now I 
> have a case where I need to give the client application (the program 
> that gets compiled) access to a variable that already exists in the host
application.

See CURRENT libtcc_test.c for an example how to access variables.

(JIT snippet needs to declare it like
     [ __attribute((dllimport)) ] extern myStruct a;
)

-- gr




> Specifically, my client program
> needs a pointer to a struct that already exists in the host 
> application during runtime. This is a basic illustration of what's going
on:
> 
>  
> 
> // Struct declaration (known in the host program and the client 
> program)
> 
> typedef struct myStruct_t {
> 
>                 .
> 
> } myStruct;
> 
>  
> 
> // Creating an instance of said struct in the host program
> 
> myStruct a;
> 
>  
> 
> // Using that struct in the client program (this gets compiled by 
> libtcc)
> 
> myFunct(&a);
> 
>  
> 
> When I compile this with libtcc, I get the compilation error "a is 
> undeclared". Initially I was confused by that because I properly added the
> struct instance using this:   tcc_add_symbol(s, "a", &a);
> 
> However, upon thinking about it (and reading the documentation) I 
> figured out that tcc_add_symbol only affects linking time and the tcc 
> compiler simply doesn't know what a is.
> 
>  
> 
> My question: Is there any way to give a client program access to a 
> variable that exists in the host program? All I could think of so far 
> is generating a wrapper function that gets compiled with the client 
> program that returns a pointer to a. However, I'd like to avoid that if
possible.
> 
>  
> 
> Any kind of comments would be greatly appreciated.
> 
>  
> 
>  
> 
> Best regards,
> 
> ~ Joel Bodenmann
> 
> 
> 
> 
> ----------------------------------------------------------------------
> --
> 
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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





reply via email to

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