Fantastic Fourier
Fantastic Fourier

Reputation: 613

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.

Upvotes: 1

Views: 804

Answers (3)

Ramakrishna
Ramakrishna

Reputation: 620

Can you please try the below.

Change the below

     int * socks[MAX_CONNECTION]; 

to

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

Accessing:

     int i = *socks[index];

Upvotes: 0

JayM
JayM

Reputation: 4908

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?

Upvotes: 1

Jim Lewis
Jim Lewis

Reputation: 45045

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?

Upvotes: 1

Related Questions