开发者

compilation error: request member in something not a structure of union

I'm having the above error request member rv in something not a structure of union. I've googled it开发者_如何学运维 and several answers told me it's when working with a pointer but tries to access it as a struct, where I should be using -> instead of .

  int foo(void * arg, struct message * msg)
  {
    struct fd_info * info = (struct something *) arg;
    struct client * csys = info->c_sys;
    int * socks[MAX_CONNECTION];
    int rv;
    socks = &(info->_socks); // where int * _socks[MAX_CONNECTION] in struct info

    // do other things

    rv = sendto(socks[i], msg, sizeof(msg), NULL, &(csys->client_address), sizeof(csys->client_address));
    ...
  }

The problem is all of the arguments i have are pointers. i'm confused as to what is wrong. thanks to any comments/thoughts.

EDIT: sorry about &msg, it was originally just msg but in my desperate attempt i was trying things. added definition of rv.


msg is already a pointer. So perhaps you should have msg instead of &msg, and sizeof(*msg) instead of sizeof(&msg), in the arguments you're passing to sendto?


I see a couple problems, but not necessarily the one that is causing your error. You'll need to provide more code and tell us where the error is occurring.

Problems: 1) why are you using &msg in the call to sendto()? msg is already a pointer. Do you mean to pass a pointer to a pointer?

2) sizeof(&msg) evaluates to the size of a pointer. Is that what you want or do you want the size of the data msg points to?

3) My guess as to the cause of your error is csys. What is it? Is it a pointer or a struct?


Can you please try the below.

Change the below

     int * socks[MAX_CONNECTION]; 

to

     int** socks;
     *socks = &(info->_socks); 

Accessing:

     int i = *socks[index];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜