??? 06/24/04 21:38 Read: times |
#73137 - RE: calling unsigned char Responding to: ???'s previous message |
Raj Shetgar said:
If you need to access any variable across various functions you need to make it a global variable If the functions are in the same file, make it 'static' http://www.8052.com/forum/read.phtml?id=72566 If the functions are in different files, you need a definition in exactly one file, and corresponding 'extern' declarations in all other files that need access to it. This is best accomplished by use of a Header File If you just need to see the value of the variable (not change the variable itself), you can pass it as a parameter: void main(void) { unsigned char x; x = 0x31; dosomething( x ); } void dosomething( unsigned char xx ) { unsigned char y; y = xx; } If you want to be able to change the value of the variable without making it global you can, with great care, use a Pointer: void main(void) { unsigned char x; x = 0x31; dosomething( &x ); } void dosomething( unsigned char *px ) { unsigned char y; y = 23; *px = y; }NOTE: This example is purely for the purposes of illustrating that it can be done; I am not saying that this is a good example of what you should do! Raj Shetgar said:
I suggest you to go through a general C book. Absolutely! None of this is specific to the 8051 - it is all perfectly standard 'C' language basics. Perhaps KR shold read K&R...? ;-) |
Topic | Author | Date |
calling unsigned char | 01/01/70 00:00 | |
RE: calling unsigned char | 01/01/70 00:00 | |
RE: calling unsigned char | 01/01/70 00:00 | |
read this thread | 01/01/70 00:00 | |
Mr Pedantic![]() | 01/01/70 00:00 |