Nick Keighley wrote:
Victor Bazarov wrote:
>Frederick Gotham wrote:
>>Grant posted:
>>>I need to write data to a physical address between 0xD0000 and
0xDFFFF
int main()
{
char unsigned *const min = (char unsigned*)0xD0000;
char unsigned const *const max = (char unsigned*)0xDFFFF;
char unsigned *p = min;
do *p++ = 5;
while (max != p);
*p = 5;
}
The code above does not guarantee to access *physical addresses*,
only *virtual* ones. Besides, there is no guarantee such virtual
addresses exist.
isn't casting an int to a pointer implemetation defined behaviour? And
isn't dereferencing the resulting pointer undefined behaviour?
Any undefined behaviour can still be defined by the implementation,
the Standard does not prohibit that. FWIW in MS-DOS ("real mode" of
x86 processors), for instance, the mechanism Frederick showed *is*
the way to access a particular location in physical memory. There
are, I am sure, other platforms that implement it that way. The only
reason it's so is that the mapping between virtual space and physical
space is 1-to-1 there.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask