views:

107

answers:

3

Hi everybody, 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.

+1  A: 

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?

Jim Lewis
Fantastic Fourier
+1  A: 

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?

JayM
A: 

Can you please try the below.

Change the below

     int * socks[MAX_CONNECTION]; 

to

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

Accessing:

     int i = *socks[index];
Ramakrishna
I actually don't get any errors with this, thanks! But how do I use it to refer to information with an index?
Fantastic Fourier
Sorry, my mistake, I was looking at wrong line number. I still get the same error.
Fantastic Fourier
Try moving the below declarations to the beggining of the function. int * socks[MAX_CONNECTION]; int rv; struct fd_info * info = (struct something *) arg; struct client * csys = info->c_sys;
Ramakrishna
Hmm they are in the beginning of the function..
Fantastic Fourier