Keil5 error: #29: expected an expression [Solved]

…/Core/Src/main.c(113): error: #29: expected an expression


preface

When defining a macro, you habitually align and type spaces, resulting in an error when calling

1. Wrong situation

#define SDA_High()   do{HAL_GPIO_WritePin(I2C_Port,I2C_SDA_Pin,GPIO_PIN_SET);}while(0)
#define SDA_Low ()   do{HAL_GPIO_WritePin(I2C_Port,I2C_SDA_Pin,GPIO_PIN_RESET);}while(0)  
//      SDA_Low ()  Spaces added for alignment

When calling the program

	SDA_Low();
	SDA_High();

Program error:
…/core/SRC/main. C (113): error: #29: expected an expression
…/core/SRC/main. C (113): error: #65: expected a “;”
solution: remove the space

Summary

Format #define identifier replacement list of macro definition
macro definition uses “identifier” to represent the content in the “replacement list”. The identifier is called the macro name. During preprocessing, the preprocessor will replace all macro names in the source program with the contents in the replacement list in the macro definition. When defining many parameters, it is recommended to use do {} while (0). For reasons, refer to the benefits of using do {} while (0) in macro definition

Read More: