### Question 19.25

How can I access memory (a memory-mapped device, or graphics memory) located at a certain address?

Set a pointer, of the appropriate type, to the right number (using an explicit cast to assure the compiler that you really do intend this nonportable conversion):

    	unsigned int *magicloc = (unsigned int *)0x12345678;

Then, `*magicloc` refers to the location you want. (Under MS-DOS, you may find a macro like `MK_FP()` handy for working with segments and offsets.)

References: K&R1 Sec. A14.4 p. 210
K&R2 Sec. A6.6 p. 199
ANSI Sec. 3.3.4
ISO Sec. 6.3.4
Rationale Sec. 3.3.4
H&S Sec. 6.2.7 pp. 171-2

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback