-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
  • 68,300
  • 10
  • 92
  • 234

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
  • 53,199
  • 16
  • 130
  • 198