Note that there are some explanatory texts on larger screens.

plurals
  1. PORe-initialize library variables in C program
    primarykey
    data
    text
    <p>I am trying to write a program where I have to call some functions through a (shared) library (its source is available). The C code for the library has several global variables, and many functions change the values of these global variables. What I have to do in my program requires that each function call that I make gets to work with a fresh set of variables.</p> <p>For example, let this function be a part of the library:</p> <pre><code>int x = 1; int foo() { int a = 0; //do somethings to 'a' //... x++; return a; } </code></pre> <p>Now every time I invoke <code>foo()</code> from my program, the value of <code>x</code> gets update from 1 to 2 then 3 then 4 and so on... I am try to construct a program so that every time <code>foo()</code> is invoked, it sees x = 1.</p> <p>I am sorry to say that my knowledge of how C/linux treat these variable spaces is insufficient, so this question may seem vague. The above is just a small example; in reality, there are so many variables that is practically impossible to reset their values manually.</p> <p>What may be the best way to compile that library and/or use it my program so as to refresh the variables?</p> <p>(On a side note, what I am also trying to do is to parallelize calls to foo(), but because of the shared variables, I cannot do that.)</p> <p>EDIT: When working on some web dev projects, I used to encapsulate some code in webservices and then invoke those services from the main program. Does a similar framework exist in C/Linux? Please note that functions are returning data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload