This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Problem with a macro
- From: Peter Gregson <pgregson1 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 20 Oct 2013 00:13:10 -0300
- Subject: Problem with a macro
- Authentication-results: sourceware.org; auth=none
Hello,
Perhaps you can help me. I have a piece of code that I am porting to GCC and one of the macros has been giving me problems for over a week. Could you please look at it and tell me what is wrong? Note that this is extracted from the actual code, and is, I think, the smallest amount that shows the problem.
First the code:
/* Test macro defs */
#define __REG16 unsigned short
#define __READ_WRITE const
typedef struct {
__REG16 EA : 4;
__REG16 STATTX : 2;
__REG16 DTOGTX : 1;
__REG16 CTRTX : 1;
__REG16 EPKIND : 1;
__REG16 EPTYPE : 2;
__REG16 SETUP : 1;
__REG16 STATRX : 2;
__REG16 DTOGRX : 1;
__REG16 CTRRX : 1;
} __usb_epr_bits;
#define __IO_REG16(NAME, ADDRESS, ATTRIBUTE) \
volatile __no_init ATTRIBUTE unsigned short NAME @ ADDRESS
#define __IO_REG16_BIT(NAME, ADDRESS, ATTRIBUTE,BIT_STRUCT)\
volatile __no_init ATTRIBUTE union\
{unsigned short NAME; \
BIT_STRUCT NAME ## _bit; \
} @ ADDRESS
int main (void) {
unsigned short USB_EP0R;
__IO_REG16_BIT (USB_EP0R, 0x40005C00,__READ_WRITE,__usb_epr_bits);
return (0);
}
Now the error message when I compile it. Note that I have "--save-temps" in the compiler invocation so that I can see the output of the preprocessor. I also used -O0 to keep things simple.
Peters-MacBook-Air:STM32F103-STK peter$ gcc -O0 --save-temps -I USB tt.c
tt.c: In function ‘main’:
tt.c:39: error: nested functions are disabled, use -fnested-functions to re-enable
tt.c:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’
tt.c:39: error: stray ‘@’ in program
tt.c:39: error: expected identifier or ‘(’ before numeric constant
Peters-MacBook-Air:STM32F103-STK peter$
When I add -fnested-functions to the command line, I get :
Peters-MacBook-Air:STM32F103-STK peter$ gcc -O0 --save-temps -I USB -fnested-functions tt.c
tt.c: In function ‘main’:
tt.c:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’
tt.c:39: error: stray ‘@’ in program
tt.c:39: error: expected identifier or ‘(’ before numeric constant
Peters-MacBook-Air:STM32F103-STK peter$
The output of the preprocessor is as follows. You can see that the macro substitution has been carried out, and it appears to my eye, correctly.
# 1 "tt.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "tt.c"
# 9 "tt.c"
typedef struct {
unsigned short EA : 4;
unsigned short STATTX : 2;
unsigned short DTOGTX : 1;
unsigned short CTRTX : 1;
unsigned short EPKIND : 1;
unsigned short EPTYPE : 2;
unsigned short SETUP : 1;
unsigned short STATRX : 2;
unsigned short DTOGRX : 1;
unsigned short CTRRX : 1;
} __usb_epr_bits;
# 35 "tt.c"
int main (void) {
unsigned short USB_EP0R;
volatile __no_init const union {unsigned short USB_EP0R; __usb_epr_bits USB_EP0R_bit; } @ 0x40005C00;
return (0);
}
I have the following questions:
1.What are my errors?
2. What is the "@" syntax about? I think that it means that he union is saved at absolute address 0x40005C00, but when I search on GCC "@" I get nothing.
Can you help me, please?
Thank you, and
Best regards,
Peter