[Top][All Lists]
[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 19:10:11 +0200 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
Karol Babioch schrieb:
I'm currently trying to check whether two macros are equal to each
other. The idea is to generate different code, when they are equal,
which basically means that they are connected to the same port.
Basically it looks something like this:
#define LED1_DDR DDRD
#define LED2_DDR DDRD
#if LED1_DDR == LED2_DDR
// Code
#endif
But when trying to compile this, I get the following error:
error: operator '*' has no left operand
That won't work.
Compile it with -save-temps and look at the generated precompiled
code in the i file to understand why it's an error.
You can write
if (&LED1_DDR == &LED2_DDR)
{
// Code
}
and let the optimizer throw away the code if the ports are different.
Interestingly enough it works just fine, when the values of the macros
are not some sort of macro itself, but a literal, e.g. "one". It then
just compiles fine.
BTW, also try the following:
#define a one
#define b two
#if a == b
#error
#endif
You cannot compare macros like that.
Could anyone explain this to me? Is there any way around this (still
using macros)?
With macros? No way here.