Read C variable in PB [Resolved]

Just starting out? Need help? Post your questions and find answers here.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Read C variable in PB [Resolved]

Post by juergenkulow »

Code: Select all

; printf under PB_C
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_Console 
  CompilerError "Exec-Format must be Console in Compiler-Option"
CompilerEndIf  
Define *string=UTF8("Hello visible universe. ")
Define *string2=UTF8("Value is now: %lld ")
Define *string3=UTF8("CPU-Time: %lld ")
Define value.q=42 
OpenConsole()
! printf(p_string); 
! printf(p_string2,++v_value);
! long long myrdtsc(void) { asm volatile ("rdtsc\n\t" "shl $32,%rdx\n\t" "or %rdx ,%rax"); }
! printf(p_string3,myrdtsc()); 
Input()
CloseConsole()
FreeMemory(*string) 
FreeMemory(*string2)
FreeMemory(*string3)
; Hello visible universe. Value is now: 43 CPU-Time: 3181639470065
Delete: CompilerIf #PB_Processor_C<>#PB_Compiler_Processor ...
Last edited by juergenkulow on Sun Jun 20, 2021 10:15 am, edited 1 time in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Read C variable in PB [Resolved]

Post by Kwai chang caine »

Juergenkulow apparently you are a C master :shock: 8)
All your codes is always splendids...but always also ununderstandable for my little head :oops:
ImageThe happiness is a road...
Not a destination
Olli
Addict
Addict
Posts: 1239
Joined: Wed May 27, 2020 12:26 pm

Re: Read C variable in PB [Resolved]

Post by Olli »

It stays a_MyArray and p.v_myVariableInTheProcedure to be tested, and you will have done the complete tour of the links between PB and C !
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Read C variable in PB [Resolved]

Post by Marc56us »

Now how to do the opposite: access from C to a variable defined by PB?

Code: Select all

A$ = "Hello World"

! printf("%s", A$ ??? );

Input()
PokeS ? strcpy(v_A[], A$ ?) ?
:?:

(My goal is to try to use the sscanf, sprintf etc functions afterwards)
:wink:
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Read C variable in PB [Resolved]

Post by juergenkulow »

Code: Select all

; PB_C sscanf
EnableExplicit
Define *a_utf8string=UTF8("4711471274713")
Define value.q
! extern int sscanf(const char *s, const char *template,...);
; First find declaration of sscanf. 
! sscanf(p_a_utf8string, "%lld" , &v_value);
; C Scan String function with the parameters
; PureBasic Pointer to a UTF8-String *a_utf8string,  p_a_utf8string
; Scanformat for quad, 8 Byte number in c long long  %lld
; Adress of PureBasic value, &v_value
SetClipboardText("Value is: "+Str(value))
MessageRequester("Value",Str(value))
FreeMemory(*A_UTF8String)
; Value is: 4711471274713
Please ask your questions.
Delete: CompilerIf #PB_Processor_C<>#PB_Compiler_Processor
Last edited by juergenkulow on Sun Jun 20, 2021 10:16 am, edited 1 time in total.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Read C variable in PB [Resolved]

Post by Marc56us »

Thank you juergenkulow for this quick answer with the explanations in the comments. :D

This new version of PB will definitely bring us many new possibilities.
:wink:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Read C variable in PB [Resolved]

Post by Kwai chang caine »

Marco_MonPoto wrote:Now how to do the opposite: access from C to a variable defined by PB?
Image

"Cé ane baune késtion !!!! é j'vous r'merci d'm'l'avoir posée !!!" :mrgreen: 8)

I see i'm not alone to play with the new wonderfull backend :wink: :lol:
Marco_MonPoto wrote:This new version of PB will definitely bring us many new possibilities.
I even believe that you are below the truth, for me ....it's really a daydream, i still can't believe it again :shock: 8)

@juergenkulow
My empire for 1% of your knowledge :shock:

Thanks a lot for completing our collection of communication instructions, between PB and C 8)
You know ....in a new couple .... it's the "good" communication the most important :lol:

Image
ImageThe happiness is a road...
Not a destination
Olli
Addict
Addict
Posts: 1239
Joined: Wed May 27, 2020 12:26 pm

Re: Read C variable in PB [Resolved]

Post by Olli »

Juergenkulow wrote:! long long myrdtsc(void) { asm volatile ("rdtsc\n\t" "shl $32,%rdx\n\t" "or %rdx ,%rax"); }
I do not find the words to describe how it is beautiful...
Post Reply