> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > On Behalf Of Ruud Vlaming > Sent: Friday, October 03, 2008 10:28 AM > To: avr-chat@nongnu.org > Subject: [avr-chat] Is this efficient? > > To find out if a register is in the io space in .c files, > i use the following, ugly, construct: > > #undef _SFR_IO8 > #define _SFR_IO8(arg) (arg) > #if (TIMSK < 0x40) > blah blah > #else > bloh bloh > #endif > #undef _SFR_IO8 > #define _SFR_IO8(arg) (*(volatile uint8_t *)((arg) + 0x20)) > > I cannot test it with _SFR_IO_REG_P, although that macro seems to be > meant for the purpose: > > #if _SFR_IO_REG_P(TIMSK) > > for that gives the error: > error: operator '*' has no left operand > > Somewhere i am missing the point i guess. > Who knows the proper way to do such things?
The _SFR_IO_REG_P() macro is designed to be used in the C code itself, not in any preprocessor statements. Something like: if _SFR_IO_REG_P(TIMSK) { // TIMSK is an IO register. } else { // TIMSK is not an IO register. } Thoroughly untested. And yes it creates more code, as it does not conditional compilation. If you look at the implementation of the _SFR_IO_REG_P() macro, it is taking the address of the register and typecasting. IIRC, the preprocessor is not that smart. It is not enough C-aware to be able to handle this in preprocessor statements. But it should work in regular C code. HTH Eric _______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat