Path: utzoo!attcan!uunet!mcvax!ukc!stl!stc!idec!camcon!mrh From: mrh@camcon.co.uk (Mark Hughes) Newsgroups: comp.sys.ibm.pc Subject: Re: Microsoft Quickc - Pointers to arbitrary memory location Message-ID: <1920@titan.camcon.co.uk> Date: 8 Sep 88 08:36:47 GMT References: <666@dogie.edu> Organization: Cambridge Consultants Ltd., Cambridge, UK Lines: 41 From article <666@dogie.edu>, by dorl@vms.macc.wisc.edu (Michael Dorl - MACC): > I've been trying to reference screen memory directly from Quickc. > The stuff I've tried looks something like this > > char far *p; > long i; > > p = (char far *)0xb8000; > for (i=0; i<0x8000; i++) { > *p = '\000'; > p++; > } > Try defining a macro like:- #define fp(a) ( (( (long)(a) & 0xf0000 )<< 12) | ( (long(a) & 0xffff ) ) and replacing your pointer assignment with:- p = (char far *)( fp( 0xb8000 ) ); The problem is caused by the way that pointers are stored, i.e. most significant word contains segment address and l.s.w. contains the offset within the segment. Unfortunately, Microsoft C does not realise that you want to point to the address 0xb8000, and simply interprets this as segment=0xb, offset 0x8000. What you want is segment=0xb000, offset=0x8000. The macro performs this conversion for you. This is a consequence of the architecture of the 8086 (etc.), but I'm not sure if the compiler should interpret your assignment in the way that it does. Intuitively, I would say that the compiler should realise that you want to point to a memory location and implement the assignment appropriately instead of blindly stuffing the value into your variable. Does anyone know what the standards say (if anything) about this? -- ------------------- or <...!mcvax!ukc!idec!camcon!mrh> | Mark Hughes | Telex: 265871 (MONREF G) quoting: MAG70076 |(Compware . CCL) | BT Gold: 72:MAG70076 ------------------- Teleph: Cambridge (UK) (0)223-358855