Microsoft C far pointer dereferencing

michael k finegan mfinegan at uceng.UC.EDU
Sun Aug 19 03:24:29 AEST 1990


julian at uhccux.uhcc.Hawaii.Edu (Julian Cowley) writes:

>In article <5843 at uceng.UC.EDU> mfinegan at uceng.UC.EDU writes:
>>>PutPixel (int x, int y, unsigned char c)
>>>{
>>>  unsigned char far *mem;
>>>
>>>  FP_SEG (mem) = 0xa000;
>>>  FP_OFF (mem) = 320 * y + x;
>>>
>>>  *mem = c;		/* <-- this line gives a run-time error */
>>>}
>>
>>If you look at the manual page again, it says the use of FP_*** is library
>>(i.e. memory model) dependent. For small and medium models, these macros
>>will only work if the pointer mem is in the default data segment. You have
>>it on the stack (subroutine automatic variables) - is that the problem ?

>Unfortunately, no. 
~
~
~
>[ps. that was using quick c, not microsoft c proper...possible bug?]
They are certainly different libraries - but try using CL /AL to compile.
>julian at uhccux.bitnet

Funny, but the following works just fine on MSC v5.1 ... Did you select option
to recompile all libraries with latest code when you installed the compiler
(the idiots at MS should make it automatic, or send latest library precompiled!)
						    - Mike
						      mfinegan at uceng.UC.EDU
--------------------------------------------------------------------------------
#include <stdio.h>
#include <dos.h>

main(argc, argv)
int argc;
char **argv;
{
	int i, j;
	unsigned char value;
	union REGS inregs, outregs;

	if(argc == 2) {
	    value = argv[1][0];
	   /* set 320 by 200 by 256 graphics using assembler like interface */
	    inregs.x.ax = 0x0013;
	    int86(0x10,&inregs,&outregs);
	    for(i=0;i<200;i++)
	        for(j=0;j<320;j++)
		    putbyte(j, i, value);
	   /* restore 80 by 25 text using assembler like interface */
	    inregs.x.ax = 0x0003;
	    int86(0x10,&inregs,&outregs);
	}
}

unsigned char far *video_byte;

putbyte(x, y, value)
int x, y;
unsigned char value;
{
	FP_SEG(video_byte) = 0xa000;
	FP_OFF(video_byte) = 320*y + x;

	*video_byte = value;
}



More information about the Comp.lang.c mailing list