开发者

passing pointers to a function

This is the prototype of my function

void classifier_rules(struct classifier *k, struct classifier *ptr_keys);

This is how I have assigned address of a pointer

struct classifier keys,*ptr_keys;
ptr_keys = &keys;

I have called this function classifier_rules in another function like this

classifier_rules(&(ptr->keys[pos]), &ptr_keys); 
here i get a error  ‘ptr_keys’ undeclared (first use in this function)

classifier_rules(struct classifier *rules, struct classifier ptr_keys )
{
 this is开发者_如何学Go the body of function;

}

hHw to remove this error, I want the address of keys to be passed failing to do so I may access some wrong memory location


If

struct classifier keys,*ptr_keys

is in your calling function, then it should work. (Or at least you should get a different error).

You shouldn't be passing &ptr_keys.

classifier_rules(&(ptr->keys[pos]), ptr_keys); 
//ptr_keys is already a pointer, you don't need to use a '&'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜