avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Check whether two macros are equal to each other


From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] Check whether two macros are equal to each other
Date: Sun, 03 Jun 2012 21:42:08 +0200
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

Joerg Wunsch schrieb:
Georg-Johann Lay <address@hidden> wrote:

Could anyone explain this to me? Is there any way around this
(still using macros)?

With macros? No way here.

Well: no way *at the preprocessor level*.

However, moving the comparison to the *compiler level* could work.
The values of e.g. DDRD and DDRB are expressions that can be compared
by the compiler.  As the resulting comparison is constant at
compile-time, with optimization enabled, those code portions that can
never be reached (due to the compile-time constant comparisons) are
optimized away.

So, turn your

#if LED1_DDR == LED2_DDR

into

  if (LED1_DDR == LED2_DDR) {

As I already wrote, the right C-level condition is

if (&LED1_DDR == &LED2_DDR)

You don't want to /read/ from the ports.

Johann






reply via email to

[Prev in Thread] Current Thread [Next in Thread]