Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!sri-spam!ames!ptsfa!ihnp4!ihnet!tjr From: tjr@ihnet.ATT.COM (Tom Roberts) Newsgroups: comp.sys.ibm.pc Subject: C routines to access memory Message-ID: <584@ihnet.ATT.COM> Date: Tue, 10-Nov-87 13:56:44 EST Article-I.D.: ihnet.584 Posted: Tue Nov 10 13:56:44 1987 Date-Received: Fri, 13-Nov-87 07:09:24 EST Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 36 To reference memory on an IBM-compatible PC, using C pointers, you must be sure that you know which compiler you are using; THEY DIFFER IN IMPORTANT WAYS!!! Turbo C: /* in L model, you can omit the "far" keyword */ char far *p; p = MK_FP(0xB800,0); *p = 'A'; /* sets B800:0000 to 'A' */ p = (char far *)0xB8000000L; /* equivalent to the MK_FP() above */ Lattice C: /* Lattice C has no "far" keyword, use L model (newer versions might) */ char *p; p = 0xB8000L; *p = 'A'; /* sets B800:0000 to 'A' */ NOTE: these two compilers use a different mapping between longs and far pointers: Turbo C simply copies them; Lattice C treats longs as a flat, uniform address (which I consider much more useful). If you mix them up, you will clobber random locations in memory. When I converted from Lattice C (v 2.15) to Turbo C (v 1.00), I did not know this, AND MY HARD DISK GOT TRASHED SEVERAL TIMES BEFORE I DISCOVERED THIS DIFFERENCE. Note also that "far pointer" in Lattice C L model, is similar to the Turbo C "huge pointer", NOT Turbo C "far pointer" (huge pointers are normalized after arithmetic, far pointers ARE NOT). Tom Roberts ihnp4!ihnet!tjr