0

I got the error message:

../usr/examples/xmpl-rpc/rpc_rpc.c: In function ‘send_myrpc’:
../usr/examples/xmpl-rpc/rpc_rpc.c:40:25: error: invalid type argument of ‘->’ (have ‘struct xmplrpc_binding’)
 err = xmplrpc_client->rpc_tx_vtbl.myrpc(&xmplrpc_client, in, &s_out);
                     ^

and the definition of xmplrpc_client is:

static struct xmplrpc_binding xmplrpc_client;

The struct xmplrpc_binding has

struct xmplrpc_rpc_tx_vtbl rpc_tx_vtbl;

And the struct xmplrpc_rpc_tx_vtbl is

struct xmplrpc_rpc_tx_vtbl {
  xmplrpc_myrpc__rpc_tx_method_fn *myrpc;
};

It's obvious that xmplrpc_client.rpc_tx_vtbl.myrpc is the wrong way, and I think the way I wrote xmplrpc_client->rpc_tx_vtbl.myrpc is correct.

What should I do to fix this error?

cstjh
  • 153
  • 1
  • 2
  • 8

2 Answers2

2

You use the -> operator when the operand (which appears to the left of the operator) is a pointer to a struct or union type, and . when the operand is an instance of a struct or union type.

So...

xmplrpc_client is declared as an instance of struct xmplrpc_binding, thus you would use the . operator to access any of it's members:

xmlrpc_client.rpc_tx_vtbl

The member rpc_tx_vtbl is declared as an instance of struct mplrpc_rpc_tx_vtbl, so again, you'd use the . operator to access any of its members:

xmlrpc_client.rpc_tx_vtbl.myrpc

Thus, your call should be written

err = xmplrpc_client.rpc_tx_vtbl.myrpc(&xmplrpc_client, in, &s_out);
John Bode
  • 119,563
  • 19
  • 122
  • 198
0

In order to fix the error you should write it this way

 xmplrpc_client.rpc_tx_vtbl.myrpc(/* and args */);

this my solve the confusion Arrow operator (->) usage in C

Community
  • 1
  • 1
codeconscious
  • 396
  • 3
  • 15