-2

I have a structure like :

struct spidev_data {
  int busy;
  int irq;
};

And I just want to access a member ( like spidev->busy ) by a define, so I try this:

#define BUSY spidev->busy

But it does not work...

Can someone tell me how to do this ?

Thanks !

alk
  • 69,737
  • 10
  • 105
  • 255

1 Answers1

3

You should try this

spidev_data *spidev = /* ... new or malloc ... */;

BUSY = 1;

But more elegant is

#define BUSY(X) (X)->busy

...

BUSY(spidev) = 1;

because it is not specially for an object.

masoud
  • 55,379
  • 16
  • 141
  • 208