i write a global.h file: #ifndef GLOBAL_H #define GLOBAL_H int nGlobal; #endif //file A.c #include "global.h" .... //file B.c #include "global.h" .... Build target 'Target 1' compiling A.c... compiling B.c... linking... *** ERROR L104: MULTIPLE PUBLIC DEFINITIONS SYMBOL: nGLOBAL MODULE: A.obj *** ERROR L104: MULTIPLE PUBLIC DEFINITIONS SYMBOL: nGLOBAL MODULE: B.obj oh,why the error do not happen when i write code "#include <reg51.h>" in several .c files. please help me,thank you very much.
As a rule of thumb, a header may contain: Type definitions:struct Point { int x, y; }; Function declarations:extern int strlen (const char*); Data declarations:extern int a; Constant definitions:const float pi = 3.14; Enumerations:enum Light {red, green, blue}; Include directives:include <stdio.h> Macro definitions:#define VERSION 12 Conditional compilation directives:#ifdef NDEBUG Comments:/*something*/ Conversely, a header never contain: Ordinary function definitions:char get(char *p) {return *p++} Data definitions:int a; Aggregate definitions:short tbl[] = {1, 2, 3}; from THE C++ PROGRAMMING LANGUAGE,Bjarne Stroustrup
thank you vrey much. I think you are right. but that is very surprising that no errors with using <reg51.h>. so i think "sfr" and "sbit" do not realy define a variable.
View all questions in Keil forum