Forum : 8051
Post Information | Post |
---|---|
June 14, 2011 - 7:31pm
|
Hello, I'm developing an application composed by multiple c files. In one file, I declared some bit variables in "bdata" space. The functions in other c files need to access these bit variables. My current codes are like that: In the Main.c file, I wrote: void main(void) ... } Then, in Func1.c file, I declare like that: void func1(void) ... The Compiler always says the two "extern sbit" declarations are invalid ---- it is quite understandable. My question is: In general, how can I access public bit variables declared in another file? Thanks in advance. Regards, WD. |
Hi,
Thanks for your report.
Your problem is that your variables are declared in the main() function body, hence they are local variables. If you need to access them as external you need to declare them outside of any function. Here is an example:
Using this, the Func1.c file will compile and the whole project will link.
Best Regards,
Hi Bruno,
I made a mistake when writing my original report. These sbit declarations are not made in main() function.
Actually, in the real codes, these declarations are made in a *.h file, and this file is included in main.c file.
So, these declarations are actually out side any functions.
Sorry about that.
WD.