Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implement MK_FP inside Microsoft C

195 views
Skip to first unread message

Gary Chan

unread,
Jan 13, 1994, 10:39:30 PM1/13/94
to

Hello, All C guru.


I know that in Turbo C, there is a command called MK_FP that can
combine the offset and segment address to a absolute address. But is there
any similar commands in Microsoft C?! if not, how can I implement this
MK_FP in Microsoft C. Pls help me as I am a C novice.......

best rgds,
Gary chan

Carle

unread,
Jan 16, 1994, 6:23:00 AM1/16/94
to
In article <CJLot...@hkuxb.hku.hk>, h901...@hkuxb.hku.hk (Gary Chan) writes...

I'm not sure of the purpose of MK_FP but Microsoft C provides
FP_SEG and FP_OFF or _FP_SEG and _FP_OFF (new version) that
take a far pointer as an argument and allow the segment and
offset to be set or extracted. To form a pointer:
FP_SEG (ptr) = Segment;
FP_OFF (ptr) = Offset;
To get the segment and offset given a ptr:
Segment = FP_SEG (ptr);
Offset = FP_OFF (ptr);
I'm not sure when the leading underscore was added. C 5.1
did not have it. C 7.0 did have.

/*------------------------+---------------------------------------
| Carle C. Henson | Opinions expressed are my own and may
| Hughes Network Systems | not be shared by anyone else on the
| hen...@lando.hns.com | planet, even if I am right. The
| Voice (301) 428-5917 | possible exception being Rush Limbaugh
| Fax (301) 428-1868 | who is always right.
+-------------------------+-------------------------------------*/

Ellster

unread,
Jan 16, 1994, 11:24:03 PM1/16/94
to
In <16JAN199...@lando.hns.com> hen...@lando.hns.com writes:

> I'm not sure of the purpose of MK_FP but Microsoft C provides
> FP_SEG and FP_OFF or _FP_SEG and _FP_OFF (new version) that
> take a far pointer as an argument and allow the segment and
> offset to be set or extracted. To form a pointer:
> FP_SEG (ptr) = Segment;
> FP_OFF (ptr) = Offset;
> To get the segment and offset given a ptr:
> Segment = FP_SEG (ptr);
> Offset = FP_OFF (ptr);
> I'm not sure when the leading underscore was added. C 5.1
> did not have it. C 7.0 did have.

Also check out:

LDS register, far_pointer ;load pointer's seg in DS and offset in register

LES register, far_pointer ;load pointer's seg in ES and offset in register

LEA ;to load offset of operand into a register

Wichert Akkerman

unread,
Jan 19, 1994, 8:25:19 AM1/19/94
to

>From: COA...@UMUC.UMD.EDU (Ellster)
>Subject: Re: implement MK_FP inside Microsoft C
>Date: 17 Jan 1994 04:24:03 GMT
>In <16JAN199...@lando.hns.com> hen...@lando.hns.com writes:

>> I'm not sure of the purpose of MK_FP but Microsoft C provides
>> FP_SEG and FP_OFF or _FP_SEG and _FP_OFF (new version) that
>> take a far pointer as an argument and allow the segment and
>> offset to be set or extracted. To form a pointer:
>> FP_SEG (ptr) = Segment;
>> FP_OFF (ptr) = Offset;
>> To get the segment and offset given a ptr:
>> Segment = FP_SEG (ptr);
>> Offset = FP_OFF (ptr);
>> I'm not sure when the leading underscore was added. C 5.1
>> did not have it. C 7.0 did have.

You can also make MK_FP yourself:

#define MK_FP (seg,ofs) ((DWORD)seg <<16 + (DWORD)ofs)

DWORD is defined in AFX.H: it's an unsigned 32 bit integer type
(unsigned long probably).


Greetings,
Wichert.


*****************************************************************************
* Wichert Akkerman - student * *
* E-mail: Akke...@stpc.wi.LeidenUniv.nl * *
* snailmail: Gardenidal 11 * *
* 2317 HV Leiden * *
* The Netherlands * (black hole) *
*****************************************************************************

Carle

unread,
Jan 24, 1994, 1:28:00 PM1/24/94
to
In article <AKKERMAN.1...@stpc.wi.LeidenUniv.nl>, AKKE...@stpc.wi.LeidenUniv.nl (Wichert Akkerman) writes...

You might multiply by 16 or shift 4. I don't think you want to shift 16.

Andre Hoekstra

unread,
Jan 31, 1994, 3:22:31 AM1/31/94
to
According to Carle (hen...@lando.hns.com):

>Wichert Akkerman wrote:
>>You can also make MK_FP yourself:
>>
>>#define MK_FP (seg,ofs) ((DWORD)seg <<16 + (DWORD)ofs)
>>
>>DWORD is defined in AFX.H: it's an unsigned 32 bit integer type
>>(unsigned long probably).
>
>You might multiply by 16 or shift 4. I don't think you want to shift 16.
And why not?
The correct MK_FP is defined above.

Andre++
--
We interrupt this program to -annoy you and -to be generally irritating - MP

John Steele

unread,
Feb 9, 1994, 11:42:19 PM2/9/94
to
In <3FEB1994...@lando.hns.com> hen...@lando.hns.com (Carle) writes:

>In article <CKHJ9...@Utwente.NL>, a...@wb.utwente.nl (Andre Hoekstra) writes...

>You are right. I was responding to the suggestion that shift and
>add could be used instead of MSCs FP_OFF and FP_SEG macros. The only
>reason that came to mind for shift and add was if you wanted to get
>the 20 bit address in which case the shift 4 would be correct. I
>would prefer the MSC macros so if I ever tried to port it I would
>get a red flag that wouldn't show up with shift and add.

Well, the above macro doesn't work for several reasons, one of them
being a space between the macro and it's arguments. A simpler, and more
portable (no AFX.H file needed, whatever that is) follows:

#if !defined(MK_FP)
#define MK_FP(seg,ofs) ((void far *) (((unsigned long)(seg) | \
(unsigned)(ofs)))
#endif

As an aside, it is generally safer to use macro arguments in parens.
If you are worried about porting to a different DOS compiler, put the
above in a #ifdef _MSC_VER ... #endif block.

Hope this helps,
John
--
#include <disclaimer.h> /* route all flames to /dev/null */
/**************************************************************************/
/* SteeleSoft Consulting | John Steele email: jst...@netcom.com */
/* Systems Analyst | */
/* Available for Contract | Most people spell COBOLSUX incorrectly... */
/**************************************************************************/

Vincenzo Romano

unread,
Feb 12, 1994, 3:29:46 AM2/12/94
to
jst...@netcom.com (John Steele) writes:

>... A simpler, and more


>portable (no AFX.H file needed, whatever that is) follows:

>#if !defined(MK_FP)
> #define MK_FP(seg,ofs) ((void far *) (((unsigned long)(seg) | \
> (unsigned)(ofs)))
>#endif

Sorry, you left out the "<<16" for the (seg) parameter!
The exact macro reads:

#define MK_FP( s,o ) \
((void far*) ((unsigned long) (o) | ((unsigned long) (s)<<16)))
maybe these are unnecessary ^-----------------------^

The 80x86 is a little endian machine so the "far" pointers have the "near"
part (aka offset) in the lower bytes.

>As an aside, it is generally safer to use macro arguments in parens.

It's highly recomended to *always* put the macro parms into () to force the
right evaluation order.

>If you are worried about porting to a different DOS compiler, put the
>above in a #ifdef _MSC_VER ... #endif block.

I thing that the "#if ! defined( MK_FP ) ... #endif" will suffice.

>Hope this helps,
> John
>--
>#include <disclaimer.h> /* route all flames to /dev/null */
>/**************************************************************************/
>/* SteeleSoft Consulting | John Steele email: jst...@netcom.com */
>/* Systems Analyst | */
>/* Available for Contract | Most people spell COBOLSUX incorrectly... */
>/**************************************************************************/

Hope this helps too,
Enzo
--
Vincenzo "Enzo" Romano .---------------------------------------.
mu...@MILES.cnuce.cnr.it | If there's a solution, why worry? |
vro...@NYX.cs.du.edu | If there's NOT a solution, why worry? |
`---------------------------------------'

Gary A. Hildebrand

unread,
Feb 12, 1994, 6:50:14 AM2/12/94
to
In <jsteeleC...@netcom.com>, jst...@netcom.com (John Steele) writes:

>Well, the above macro doesn't work for several reasons, one of them
>being a space between the macro and it's arguments. A simpler, and more
>portable (no AFX.H file needed, whatever that is) follows:
>
>#if !defined(MK_FP)
> #define MK_FP(seg,ofs) ((void far *) (((unsigned long)(seg) | \
> (unsigned)(ofs)))
>#endif

Still not right. Here's a better one:

#if !defined(MK_FP)
#define MK_FP(seg,ofs) ((void far *)(((unsigned long)(seg) << 16) | \
(ofs)))
#endif

Regards,

Gary
--
/ Gary A. Hildebrand Internet: g...@mew.mei.co.jp \
/ Matsushita Electric Works, Ltd. UUCP: uunet!mew.mei.co.jp!gah \
/ 13-2, Mita 5-chome, Minato-ku Fax: 03-3451-0793 \
/ Tokyo 108, JAPAN Tel: 03-3452-4941 \

0 new messages