[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Preprocessor question
From: |
Thomas D. Dean |
Subject: |
[avr-gcc-list] Preprocessor question |
Date: |
Fri, 2 May 2008 19:03:08 -0700 (PDT) |
I have a question about preprocessor syntax.
I want to declare som macros that ease controlling port assignments.
in the include file, I have
#define GLUE(a, b) (a##b)
#define PORT(x) (GLUE(PORT, x))
#define PIN(x) (_BV((x)))
#define DDR(x) (GLUE(DDR, x))
#define SET_INPUT(x) ( GLUE(x, _DDR) |= ~GLUE(x, _PIN ) )
#define SET_OUTPUT(x) ( GLUE(x, _DDR) |= GLUE(x, _PIN ) )
#define SET_BIT(p,b) (p |= b)
#define CLR_BIT(p,b) (p &= ~b)
#define LEFT_MOTOR_DIR_PORT PORT(C)
#define LEFT_MOTOR_DIR_PIN PIN(3)
#define LEFT_MOTOR_DIR_DDR DDR(C)
In the .c file, I have
#include <avr/io.h>
#include <macro.h>
int main() {
SET_INPUT(LEFT_MOTOR_DIR);
return 0;
}
# avr-gcc -mmcu=atmega16 -Wall -Wmissing-prototypes -Os -I.
-I../../../asus-avr-1.0/include -E -o xx macro.c
and, in xx
...
int main() {
( ((GLUE(DDR, C))) |= ~(((1 << ((3))))) );
return 0;
}
The macro is fully expanded on the RHS, but, not the LHS
What did I do wrong?
tomdean
- [avr-gcc-list] Preprocessor question,
Thomas D. Dean <=