Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tcc compileOnce
#1
Hi,
The following code is executed multiple times and the variable values will continue to stack. How to reset it?
I need to recompile the code every time it is executed
PS: I have some difficulties in understanding C language programming and pointer variables

Thank you in advance for any suggestions and help!
david

[Image: a.gif]
Macro Tcc2
Code:
Copy      Help
dll- "" $str_add $a $b

__Tcc+ t

int compileOnce
;int compileOnce=32

__Tcc+ t
if !t.f or !compileOnce
,t.Compile("" "add" 0|compileOnce)
,&str_add=t.f

out str_add("hello" " world!")


#ret
char* add(char* a, char* b)
{
,printf("%s: a=%s, b=%s", __func__, a, b);
,strcat(a, b);
,return a;
}
#2
C is a very unsafe language and can be used only when you fully understand how the code works. Your C function does some bad things. Afterwards you'll notice some strange things happening in some unrelated places in QM and will be very difficult to find the reason.
#3
Wink  Thanks for your reminder, it is indeed like this, sometimes QM will automatically close

PS: The C code above was written with the help of ChatGPT

In the TCC example in QM, the return values are all integers. Sometimes I find some C++functions that return strings, so I tried the above,

The above code is very short. Is there a simple solution? Or can you provide an example of a function that returns a string type?
#4
Google for how to return a string in C.
#5
Another solution provided by ChatGPT, currently no issues have been identified

Additionally, (I don't want to generate a DLL) how to release C code resources in memory in QM, just like UnloadDll....

Macro Tcc2
Code:
Copy      Help
dll- "" $str_add $a $b

int compileOnce
;int compileOnce=32

__Tcc+ t
if !t.f or !compileOnce
,t.Compile("" "add" 0|compileOnce)
,&str_add=t.f

out str_add("hello" " world!")


#ret
char* add(char* a, char* b)
{
,printf("%s: a=%s, b=%s", __func__, a, b);
,char* result = malloc(strlen(a) + strlen(b) + 1);
,strcpy(result, a);
,strcat(result, b);
,return result;
}
#6
Now only a memory leak.
Quote:how to release C code resources in memory
I don't remember, probably a __Tcc variable releases the compiled code memory when dying. Use local variable or thread variable.
#7
thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)