Dereferencing Typecast Integer Literals

Andreas Krey krey at i30fs1.ira.uka.de
Tue Feb 5 02:59:53 AEST 1991


In article <22700 at netcom.UUCP>, avery at netcom.UUCP (Avery Colter) writes:
> 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.
> 

In C you may even define macros to make it more readable,
but it IS system dependent...
All macros cast the integer address to an appropriate pointer type
and then dereference it to get the lvalue/function.

#define LOC(x) (*((unsigned char*)(x)))
#define CALL(x) (((void (*)())(x))())

*(void (*()))0xFC58()

'BASIC'   <=>  'C'
a=PEEK(b) <=>  a=LOC(b);
POKE(b,c) <=>  LOC(b)=c;
CALL(x)   <=>  CALL(x);

If you want Parameters for Call:

#define FUNC(x) ((void (*)())(x))

CALL(f,a,b) <=> FUNC(x)(a,b);

(No Warranty for BASIC Syntax.)

Andy

-------------------------------------------
.signature: No such file or directory
.signature: Still no such file or directory



More information about the Comp.lang.c mailing list