tjr@ihnet.UUCP (11/12/87)
> Use these sparingly! > > #define PEEK(loc) (*(char *)(loc)) > #define POKE(loc,value) *(char *)(loc) = (value) > > To access a wide datum than a byte, change "char" to "short" or "long". BEWARE! These work fine on a VAX, or other non-segmented machine; on an 8086-based machine (like an IBM PC or compatible), there is a lot more going on. A C programmer MUST be aware of the underlying hardware architecture, and of the different memory models provided by the C compiler to utilize that hardware. In the most common memory model (SMALL), the above macros will not let you reference outside of your DGROUP "segment" (DGROUP is a segment to the HW, but a "group" to the linker - thanks a bunch Microsoft (:-(); there is almost no point to such macros in SMALL memory model - PEEK() and POKE() are usually used to reference the OS or the memory-mapped display - things which are outside of DGROUP. Writing PEEK() and POKE() macros is compiler dependent - you are better off using the library routines usually supplied by the compiler manufacturer. ANOTHER GOTCHA: different compilers convert (long) to (char far *) in different ways: Turbo C: 0xB8000000L => B800:0000 Lattice C: 0x000B8000L => B800:0000 (other compilere probably use one of these - I don't know). Tom Roberts ihnp4!ihnet!tjr