c - Expected expression before 'struct' - Error -


i'm using crossstudio ide make simple function prototype initializes uart baudrate , other parameters stm32f30x arm processor. goal of function prototype print baudrate initialization peripheral (stm32f30x.c), expected '9600'. instead error "expected expression before 'usart_init'" returned. there 3 files in total:

1) config_uart.c -> contains function prototype 2) stm32f30x_usart.c -> contains initializing function, call config_uart.c 3) stm32f30x_usart.h -> contains prototype struct definition 

config_uart.c body

void comm_initial (void) {     typedef struct usart_init usart_init;     void usart_structinit(usart_initstruct);     printf("%d\n", usart_init->usart_baudrate); } 

from stm32f30x_usart.c body

void usart_structinit(usart_inittypedef* usart_initstruct) {     /* usart_initstruct members default value */     usart_initstruct->usart_baudrate = 9600;     usart_initstruct->usart_wordlength = usart_wordlength_8b;     usart_initstruct->usart_stopbits = usart_stopbits_1;     usart_initstruct->usart_parity = usart_parity_no ;     usart_initstruct->usart_mode = usart_mode_rx | usart_mode_tx;     usart_initstruct->usart_hardwareflowcontrol = usart_hardwareflowcontrol_none; } 

from stm32f30x_usart.h body

typedef struct {     uint32_t usart_baudrate;     uint32_t usart_wordlength;     uint32_t usart_stopbits;     uint32_t usart_parity;     uint32_t usart_mode;     uint32_t usart_hardwareflowcontrol; } usart_inittypedef; 

i'm unsure error i've tried multiple variations in attempt identify problem, closest i've gotten. not understanding? appreciated.

void comm_initial (void) {     typedef struct usart_init usart_init; 

i don't see type struct usart_init defined anywhere. typedef still permitted, refers incomplete type.

you have type named usart_inittypedef has member named usart_baudrate.

    void usart_structinit(usart_initstruct);     printf("%d\n", usart_init->usart_baudrate); } 

usart_init type name. -> operator requires expression of pointer-to-struct or pointer-to-union type left operand.

if replace usart_init expression of type usart_inittypedef*, should able evaluate expression.

note %d requires argument of type int, not uint32_t. there several ways print uint32_t value; simplest is:

printf("%lu\n", (unsigned long)some_pointer->usart_baudrate); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -