Page 2 of 2
Re: embedding C code
Posted: Thu Jun 08, 2023 4:03 am
by jassing
how do you get a variable to exist 'globally' in C?
Normally, you just declare it outside of a procedure & it exists unless you declare another with the same name inside a block.
Code: Select all
! int i;
Procedure abc()
Protected j
!v_j = ++i;
ProcedureReturn j
EndProcedure
Debug abc()
doesn't work.
Is there some documentation on the restrictions of embedded code?
Re: embedding C code
Posted: Thu Jun 08, 2023 8:19 am
by mk-soft
Global module variables
[modulename]Xg_[variable]
Code: Select all
DeclareModule xyz
Declare test()
EndDeclareModule
Module xyz
Global myval2=1024
Procedure test()
Protected r1
!v_r1 = xyzXg_myval2;
ProcedureReturn r1
EndProcedure
EndModule
r1 = xyz::test()
Debug r1
Get this IDE-Tool:
https://www.purebasic.fr/german/viewtop ... 93#p361093
Re: embedding C code
Posted: Thu Jun 08, 2023 8:41 am
by idle
Take a look at my tool and the examples, raylib 4 for instance. Search for pbcex.
Re: embedding C code
Posted: Thu Jun 08, 2023 8:44 am
by mk-soft
jassing wrote: Thu Jun 08, 2023 4:03 am
how do you get a variable to exist 'globally' in C?
Normally, you just declare it outside of a procedure & it exists unless you declare another with the same name inside a block.
Code: Select all
! int i;
Procedure abc()
Protected j
!v_j = ++i;
ProcedureReturn j
EndProcedure
Debug abc()
doesn't work.
Is there some documentation on the restrictions of embedded code?
In the c-code, the procedures are written first, then the inline c-code outside of procedures. Thus the variable "i" is missing in the prcocedure.
See c-code output
Re: embedding C code
Posted: Thu Jun 08, 2023 12:56 pm
by jassing
mk-soft wrote: Thu Jun 08, 2023 8:44 am
In the c-code, the procedures are written first, then the inline c-code outside of procedures. Thus the variable "i" is missing in the prcocedure.
out of order code - got it. thanks.
Re: embedding C code
Posted: Thu Jun 08, 2023 4:58 pm
by jassing
mk-soft wrote: Thu Jun 08, 2023 8:19 am
Global module variables
[modulename]Xg_[variable]
Thanks!
Seems you can exploit C to get variables declared outside of a module, too.