Dereferencing Typecast Integer Literals

Avery Colter avery at netcom.UUCP
Mon Feb 4 07:28:46 AEST 1991


I would like to know something.

In BASIC (waiting for the groans to subside), there were the POKE, PEEK,
and CALL commands, which respectively store a value in a location, read
the present value of a location, or start executing a machine language
function starting at the location.

Now, obviously, in C, the most obvious way to do any of these is to declare
a char pointer. Dereferencing this pointer as an r-value PEEKs, dereferencing
it as an l-value POKEs, and dereferencing it with a parameter list postfixed
CALLs.

However..... since all pointer objects are pseudo-integer in nature, and since
they are considered to be typecast cousins of the true integers, my question
is whether it is necessary to even declare a pointer for these tasks.

I can't find any explicit reerence to it in either of the books I have,
so what I'd like to know is:

1. Since a constant literal integer of the appropriate size for the
implementation can be typecast into a pointer to any type, is it then 
possible to dereference the result of this typecast expression?

i.e.

{
char s;
...
s = *(char *)0xC000; /* C000: address of the keyboard strobe on Apple II */
...
}

2. If #1 can be done, then can a dereferenced typecast integer constant
be used as an l-value?

i.e.

*(char *)0xC010 = 0; /* C010: value zeroed to signal ready to take another
			  character into C000 			    */

3. Can a DTIC have a parameter list postfixed to make it into a function call?

i.e.

*(void (*()))0xFC58();  /* FC58: address of firmware HOME function */

What's the consensus on all this? Is it better to just declare const
pointer objects for all the firmware points you wish to have on hand?


-- 
Avery Ray Colter    {apple|claris}!netcom!avery  {decwrl|mips|sgi}!btr!elfcat
(415) 839-4567   "I feel love has got to come on and I want it:
                  Something big and lovely!"         - The B-52s, "Channel Z"



More information about the Comp.lang.c mailing list