[Solved] Keil error: #101: “name“ has already been declared in the current scope

 

Keil compilation error

 

#include <stdio.h>
#include <stdlib.h>
...

#define Result_TIMOUT               3
#define Result_INTIAL               0
#define Result_ERROR                1

... 
typedef enum
{
    MD_INIT,
    HARDWARE_CHECK, 
    FILESYSTEM,     
    BS_SEARCH,      
    BS_REGISTER,    
    BS_REG_CHK,     
    ME_FC_INIT,
		ME_SOCKET,	
    ME_READY
}STATUS_MACHINE_INDEX;

... // struct, enum, union

extern md_Socket_CB 			SocketOpen_CB;
extern md_Socket_CB 			SocketClose_CB;

... 

Solution:

Use conditional compilation to prevent header files from being included repeatedly. Take the above code as an example

#ifndef __MODEM_H__
#define __MODEM_H__

#include <stdio.h>
#include <stdlib.h>
...

#define Result_TIMOUT               3
#define Result_INTIAL               0
#define Result_ERROR                1

... 
typedef enum
{
    MD_INIT,
    HARDWARE_CHECK, 
    FILESYSTEM,     
    BS_SEARCH,      
    BS_REGISTER,    
    BS_REG_CHK,     
    ME_FC_INIT,
		ME_SOCKET,	
    ME_READY
}STATUS_MACHINE_INDEX;

... // struct, enum, union

extern md_Socket_CB 			SocketOpen_CB;
extern md_Socket_CB 			SocketClose_CB;

...

#endif

Keil compiled successfully

Read More: