CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to get values back from c function ?

 



ningji
Novice

Nov 11, 2012, 6:07 PM

Post #1 of 6 (3170 views)
How to get values back from c function ? Can't Post

so i have a c code, it has 2 APIs,
get_val(int &val1, int &val2);
set_val(int val1, int val2);

from perl, when i want to set new value,
`c_program $val1 $val2`;

to get value back from c program,
how to get 2 values back now ?

many thanks !


ningji
Novice

Nov 11, 2012, 6:47 PM

Post #2 of 6 (3168 views)
Re: [ningji] How to get values back from c function ? [In reply to] Can't Post

will this work ?

`c_program get_val \$var1 \$var2`

In Reply To


Laurent_R
Veteran / Moderator

Nov 11, 2012, 11:13 PM

Post #3 of 6 (3162 views)
Re: [ningji] How to get values back from c function ? [In reply to] Can't Post

Difficult for me to say, we don'ty know anything about your functions, but your first function expects a pointer to the int values. Passing a reference to your variables seems to be the right way to do so (and that's what I am doing quite regularly when calling relatively similar libraries). As for the second function, it expects values, so you would need to pass directly your variables.

I am a but surprised, though, that your C functions don't return any values (not even an error code).


ningji
Novice

Nov 12, 2012, 4:01 PM

Post #4 of 6 (3135 views)
Re: [Laurent_R] How to get values back from c function ? [In reply to] Can't Post

actually i found another way around it, thanks !


Laurent_R
Veteran / Moderator

Nov 13, 2012, 10:28 AM

Post #5 of 6 (3128 views)
Re: [ningji] How to get values back from c function ? [In reply to] Can't Post

And can you telle what this other way is, for the benefit of the communauty?


ningji
Novice

Nov 13, 2012, 11:53 AM

Post #6 of 6 (3126 views)
Re: [Laurent_R] How to get values back from c function ? [In reply to] Can't Post

sure, actually it has nothing to do with perl.

my c code is like this
void get_func(int *v1, int *v2, int *v3);

instead of playing with call by reference,
i just added 1 line in get_func,
cout << *v1 << " " << *v2 << " "<< *v3<<endl;

in perl i can just split the out into 3 ints.



In Reply To
And can you telle what this other way is, for the benefit of the communauty?


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives