Quantcast
Viewing all articles
Browse latest Browse all 3

Pass variables to other functions in C

I have the following code in C:

int main(int argc, char **argv) {

    ...

    redisContext *c;
    redisReply *reply;

    ...

    outer_function(...)

    return 0;

}

I would like to use the Redis variables in the outer_function.

I've tried to add a struct for this before main(...):

typedef struct {
    redisReply reply;
    redisContext c;
} redisStuff;

And in main:

redisContext *c;
redisReply *reply;

redisStuff rs = { reply, c };

...

outer_function((u_char*)&rs, ...)

And finally in my outer_function:

void outer_function(u_char *args, ...) {
    redisStuff *rs = (redisStuff *) args;
    reply = redisCommand(c, "MY-REDIS-COMMAND");
    ...    
    return;
}

But it fails with:

warning: incompatible pointer to integer conversion initializing 'int' with an expression of type 'redisReply *' (aka 'struct redisReply *')

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>