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
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.
+-------------------------+-------------------------------------*/
> 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
>> 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) *
*****************************************************************************
You might multiply by 16 or shift 4. I don't think you want to shift 16.
Andre++
--
We interrupt this program to -annoy you and -to be generally irritating - MP
>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... */
/**************************************************************************/
>... 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? |
`---------------------------------------'
>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 \