We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
What is the difference between the following two variable declaration?
unsigned char var; and unsigned char data var;
Without 'data', var is allocated in the default memory space according to the memory model you have selected. With 'data', var is explicitly allocated in the data memory space.
In both the cases, wont the memory allocation for "var" be in the RAM? Then how do the two differ?
Could you explain - allocation in default memory space according to the memory model...?
"In both the cases, wont the memory allocation for "var" be in the RAM? Then how do the two differ?"
Alright then, more specifically, without 'data', var is allocated in the default RAM memory space according to the memory model you have selected. With 'data', var is explicitly allocated in the internal RAM's directly addressable data memory space.
You need to read your User's Guide.
http://www.keil.com/support/man/docs/c51/c51_extensions.htm
Will do thru the link... & will get back to you incase of further queries...
Thank you.
Hello Sir,
Got the difference. The memory alocation depends on the "memory model" you select. Accordingly, a byte will be allocated at the appropriate place.
Thank you for the link.
Regards, Dipen
"The memory alocation depends on the 'memory model'"
The first one depends upon the memory model; the second one doesn't, because it specifies the memory space explicitly.
Yes exactly. Now I have understood it properly.
Now what if there isnt any external memory IC (RAM) connected & you select a model other than SMALL?
According to me, all operations with that variable will be done with a "garbage" value.
Your question implies is that the assembler/compiler/linker should 'know' what you have, it does not, unless you tell it what you have.
Erik
"According to me, all operations with that variable will be done with a "garbage" value."
Yes, that's right.
If you tell the tools to use XRAM they will do so. As Erik says, they have no way of knowing what may or may not be present in your target hardware - they just do as they are told.