Re: equivalent to far in linux/unix
From: Andre Majorel (amajorel_at_teezer.fr)
Date: 08/28/04
- Next message: Andre Majorel: "Re: Xah Lee's Unixism"
- Previous message: Pascal Bourguignon: "Re: loop in class definition ?"
- In reply to: Andrew Falanga: "equivalent to far in linux/unix"
- Next in thread: Jem Berkes: "Re: equivalent to far in linux/unix"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Aug 2004 14:07:04 +0000 (UTC)
On 2004-08-27, Andrew Falanga <falandr@hp.com> wrote:
> In any event, I was wondering if anyone here could tell me what the far
> type would translate too in linux? For example, how would I read a line
> like this?:
>
> void far *LinkAddress;
>
> What the heck is going on there? I thought void was a type. How can
> you have two types for the same variable? Would that simply be
> something like?:
>
> int *LinkAddress;
Yes. To port DOS C code to a flat memory model environment such
as i386 Linux, you can just remove the "far" and "huge"
qualifiers, and use malloc() instead of farmalloc() and halloc()
and free() instead of farfree() and hfree().
#define far
#define farmalloc malloc
#define farfree free
#define huge
#define halloc malloc
#define hfree free
The "far" and "huge" qualifiers are an artefact of the segmented
architecture of the 8086. On the 8086, pointers can be 16-bit
long or 32-bit long. A "far" or "huge" qualifier states that
this is a 32-bit pointer. This is necessary when you have more
the 64 kB of code or data.
Conversely, "near" states that this is a 16-bit pointer.
In the absence of a qualifier, pointers use the default model,
which can be near, far or huge, as specified by the relevant
compiler flags.
> It sounds as though far is typedef'd as some sort of 32 bit int.
> Perhaps, I could be totally wrong too.
"far" means that the pointer is made of a 16-bit segment number
plus a 16-bit offset. The total size is indeed 32-bit although
the addressable space is only 20-bit because the 8086 calculates
the effective address like this : segment << 4 + offset.
A "near" pointer is just a 16-bit offset. The segment number is
implied and comes from the relevant segment register (CS for
code, DS for data, etc.) The advantage of near pointers is that
they're small and fast. The drawback is that you're limited to
64 kB of code and 64 kB of data.
"huge" is the same thing as "far" except that the object can be
larger than 64 kB.
-- André Majorel <URL:http://www.teaser.fr/~amajorel/> "See daddy ? All the keys are in alphabetical order now."
- Next message: Andre Majorel: "Re: Xah Lee's Unixism"
- Previous message: Pascal Bourguignon: "Re: loop in class definition ?"
- In reply to: Andrew Falanga: "equivalent to far in linux/unix"
- Next in thread: Jem Berkes: "Re: equivalent to far in linux/unix"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|