:On 27 Feb 2005 02:19:12 -0800, in comp.lang.c , (e-mail address removed)
Wong) wrote:
:>OK. To ease the pain. Let's define this,
:> *(int *) 0x0100 = SOME_PARAMETERs; // SOME_PARAMETERS is a value
:Now you have a bunch of illegal code. You're making a pointer out of an
:integer. Pointers aren't integers, so don't do that.
I'm going by memory here, but if I recall correctly,
casting an integral value to a void pointer is not illegal: instead,
if memory servers, it has "implimentation defined results".
I seem to recall that K&R used to guarantee that a void* could be
converted to an unsigned long and back again, but that direct conversion
to/from any other kind of pointer was not part of the language specs.
To this end, note that printf("%p") and scanf("%p") are defined in
the standard as having implimentation defined interpretation but that,
If the input item is a value converted
earlier during the same program execution, the pointer that results
shall compare equal to that value.
The point here being that the barrier between numbers and pointers
is at least slightly porous, rather than the conversion being
strictly illegal as implied by your reply.
To be conforming [but with implimentation defined behaviour] I
believe the code would have to be written as
*(int *)(void *) 0x0100 = SOME_PARAMETERs;
Certainly this could be expected to memory fault in any modern
multi-user "hosted" implimentation... but back in the PDP RT11/RSX11M
and Motorolal 68000 days, it would have done something useful
[i.e., set up a trap vector.] I seem to recall also having encountered
microprocessors that did console UART I/O at something pretty close
to that address location; I've forgotten now which architecture that was.