One HAL head file: /**********************************/ #ifndef __HAL_H__ #define __HAL_H__ #define DATA_BUS P0 // sbit MCU_TXD = P1^0; // sbit MCU_RXD = P1^1; // sbit MCU_NC = P1^2; sbit D12_A0 = P1^3; sbit MCU_INT1 = P1^4; // sbit MCU_RST = P1^5; sbit WR_N = P1^6; sbit RD_N = P1^7; sbit LED1 = P3^0; sbit LED2 = P3^1; #define A0_COMMAND D12_A0=1 #define A0_DATA D12_A0=0 #define DATABUS_READ(x) DATA_BUS = 0xFF; D12_RD_N = 0; x = DATA_BUS; D12_RD_N = 1 #define DATABUS_WRITE(x) D12_WR_N = 0; DATA_BUS = x; D12_WR_N = 1 #define DISABLE EA=0 #define ENABLE EA=1 #endif /**********************************/ While compiling, it is reported that on every C file containing the head file: ERROR C231:'D12_A0' redifinition ERROR C231:'WR_N' redifinition ERROR C231:'RD_N' redifinition No other place in the project define these three, I have searched for within but no discovery. If i rem all definitions but these three in this head file, nothing change. If i merely rem these three and left others untouch, no compiling error any more.
Thanks,Mark. It's quite similar mistake, but I don't take it as the same case. The sbit definition is a special address maping and the error report is generated at the early stage of compiling while compiler is checking GLOBAL marco definiton. In contrast, the variant definiton check is at the late stage of compiling while compiler is doing scope check of variants. In different file or different place of the same file, the same marco can be define with different value. Variant can not be redefine. By the way, I can not accept the method that that post mentioned. It will make maintanence more difficult as it was before the ifndef-def-endif appear.
By the way, I can not accept the method that that post mentioned. It will make maintanence more difficult as it was before the ifndef-def-endif appear. For easier maintenance you may use the following approach: In your C code files place a definition like
#define SENSORS_MODULE
#ifndef SENSORS_H #define SENSORS_H #ifdef _DECL #undef _DECL #endif #ifdef SENSORS_MODULE #define _DECL #else #define _DECL extern #endif _DECL UI16 GetVoltage(); _DECL UI8 ui8_SomeVariable; #endif // SENSORS_H