Article View: comp.windows.ms.programmer
Article #3023casting near & far pointers
From: Chris Graham
Date: Wed, 29 May 1991 17:41
Date: Wed, 29 May 1991 17:41
77 lines
3315 bytes
3315 bytes
* Original <23 May 91 00:16:27> was from Rhoda Neimand to All
> RN: From: rhoda@mercury.sybase.com (Rhoda Neimand)
> RN:
> RN: A unix person has just asked me a curious question. I'm kind
> RN: of puzzled
Yes, unix people tend to do that to us. :-)
> RN: because I've never thought of doing this before. To me, a
> RN: far pointer
> RN: is a far pointer and a near pointer is a near pointer, period.
Good enough for me.
> RN:
> RN: His questions:
> RN:
> RN: Can you cast a far pointer to a near pointer? My answer is
> RN: that if you did,
> RN: you would lose its "farness", therefore it would no longer
> RN: point to anything
> RN: unless you were sure that its segment address was currently
> RN: in DS. Is this
> RN: correct?
Yup. You loose the segment address and are left only with the offset. This can
be very dangerous indeed. Especially when doing lost of nasty segment work.
> RN:
> RN: Can you cast a near pointer to a far pointer?
No problem. This is safe.
>RN: Not sure here. If you did,
> RN: would the segment address be 0?
I don't think so, in the assembly I've looked through, DS is generally pushed.
>RN: Does having a segment address of 0 mean
> RN: something special?
Yes, this is where the 80x8x series of processors keep their interrupt vectors.
The IBM PC BIOS uses segment 40h ( or 0:0400h ) as the BIOS data area. In any
mode pointing to anywhere ( that is not owned by yourself ) is a very dangerous
thing to do. Hence, under DOS bad code can be hard to find. In a protected mode
environment, such as OS/2 or Windows in 286/386 modes, the memory protection
will trap this and nail your program - before it does any damage.
> RN: MAKEINTRESOURCE does something like this.
> RN: I am actually confused about the purpose of MAKEINTRESOURCE.
Have a look in Petzolds Book:
First edition ( the grey one ), page 335-336
Second edition ( the white one ), page 313-314
It explains the special case of having a segment value of zero.
> RN:
> RN: I feel that either casting is not meaningful. Is this correct?
Yes they are. See above.
> RN:
> RN: Thanks
No problems. Hope this helps.
> RN: ----------------------------------------------------------------------
> RN: Rhoda Neimand [I speak for myself]
> RN: {sun,lll-tis,pyramid,pacbell}!sybase!rhoda -or- rhoda@sybase.com
> RN: "I didn't want to, Jim" Mr. Spock in _This Side Of Paradise_
> RN: ----------------------------------------------------------------------
Note my tag line.
Technical Details
Message-ID:
<funpack118008@f1.n6000.z2.fidonet.org>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!uunet!math.fu-berlin.de!unido!rwthinf!slcdec!hippo!f1.n6000.z2.fidonet.org!f344.n632.z3.fidonet.org!Chris_GrahamShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!uunet!math.fu-berlin.de!unido!rwthinf!slcdec!hippo!f1.n6000.z2.fidonet.org!f344.n632.z3.fidonet.org!Chris_Graham From: Chris_Graham@f344.n632.z3.fidonet.org (Chris Graham) Newsgroups: comp.windows.ms.programmer Subject: casting near & far pointers Message-ID: <funpack118008@f1.n6000.z2.fidonet.org> Date: 29 May 91 17:41:52 GMT Article-I.D.: f1.funpack118008 Reply-To: Chris_Graham%f344.n632.z3@hippo.dfv.rwth-aachen.de (Chris Graham) Organization: WarpSpeed Computers BBS - Home of Windows Chess Lines: 78 Comment-To: Rhoda_Neimand@f1.n6000.z2.fidonet.org (Rhoda Neimand)