In article <11**********************@m7g2000cwm.googlegroups. com>,
<am******@gmail.comwrote:
>I would like to allocte memory, but I want it to start at a predefined
address.
I have a program that writes data to ROM in an embedded device and I
would like to state where it goes.
Can this be done and how?
There is nothing in the Standard that would definitely allow you to
do this, and there is nothing in the Standard Library that allows
you to request that dynamic memory be allocated (or memory
permissions be granted to it) at any specific address.
There is, in other words, no fully portable method of doing what you ask.
However, it is within the terms of the Standard to -allow- implementations
to support casting integers to become pointers; what happens when you
do so is implementation defined.
For example, it is allowed for implementations to make meaningful
NVram_ptr = (unsigned char *)0x03E00000;
strcpy( &NVram_ptr[10], "nOW iS tHE tIME" );
but what this actually does would be up to the implementation.
(It wouldn't necessarily write at physical location 0x03E0000A --
it would be legitimate for an implementation to interpret
casting 0x03E00000 as a pointer to mean something like
"the address is at offset 0xE00000 from segment register #3". Or worse.)
Some operating systems provide tools that allow extern variables to
be placed at particular locations; for anything like that you would
need to look closely at the documentation of your linker.
--
All is vanity. -- Ecclesiastes