Results 1 to 4 of 4
Is there anyway where I can store a variable at odd address location.
Ex: int* s;
In the above i want to allocate memory with starting address as odd number....
- 09-17-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 21
variable storing in odd address
Is there anyway where I can store a variable at odd address location.
Ex: int* s;
In the above i want to allocate memory with starting address as odd number.
- 09-17-2009 #2Just Joined!
- Join Date
- Mar 2008
- Location
- Chennai, India
- Posts
- 26
But why?
Yes, You can if your compiler allows you to.
for example SDCC, a retargettable C compiler, allows you to declare variable storage locations by using __at keyword.
* Check your system documentation and don't try this if you are not sure about what you want to do. The results can be unpredictable. On GCC you may endup with a segmentation fault.
- 09-17-2009 #3
It also depends on whether your CPU architecture allows it. Some architectures don't allow multi-byte data types (like integers, floats, etc.) to reside at odd addresses. Attempting to store a multi-byte value at an odd address can result in a runtime exception in that case.
Of course, if the compiler knows ahead of time that the value will be at that address, it can implement the correct sequence of calls to pull that data from memory into a register, or store the data from a register back into memory... If the architecture doesn't support non-aligned access, it's still possible, it just takes longer (multiple fetches, some bit shifts, etc...) because you can't use the regular old "store" and "fetch" operations.
- 09-21-2009 #4


Reply With Quote
