www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/07/17:05:52

Date: Tue, 7 Feb 95 11:03:21 -0500
From: dj AT stealth DOT ctron DOT com (DJ Delorie)
To: A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk
Cc: DJGPP AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Funny error in class

> (1) dj AT stealth DOT ctron DOT com (DJ Delorie) wrote:-
> > I don't recommend using the farns* [= _farnspeekw() etc, in <sys/farptr.h>]
> > functions inside other functions. It's not safe. You don't know what someone
> > else might have done with the segment registers between calls.
> 
> But my program is almost entirely composed of functions calling functions
> calling functions several deep! Hardly any of it is in main(). If I can only
> use the _farns*() functions in main(), I can't use them. Can I then use the
> _far*() functions that do specify a `selector', and put the `unsigned short
> selector' argument as 0?

It's not impossible to do it your way, just be warned that your
functions can't GUARANTEE that the segment registers have the right
values.  The _farns* functions were intended to be used in an enclosed
function, like one that loops through a chunk of video memory, where
you know that there's no opportunity for someone else to use a _far*
function.  All it takes is someone calling _far* (say, to get a BIOS
value) and you're toast.

> (2) In the peek and nspeek functions in <sys/farptr.h>, e.g.:-
> 
> why not output straight to the result register al/ax/eax?, thus?:-

gcc optimizes it down to that, but my way has two advantages:

(1) There's no reliance on values being returned in eax.

(2) The compiler doesn't print any warning messages about no value
    being returned.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019