Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!ns-mx!ccad.uiowa.edu!cadsi From: cadsi@ccad.uiowa.edu (CADSI) Newsgroups: comp.windows.ms.programmer Subject: Re: casting near & far pointers Message-ID: <1991May23.145820.25248@ccad.uiowa.edu> Date: 23 May 91 14:58:20 GMT References: <12902@sybase.sybase.com> Organization: CAD-Research, U. of Iowa, Iowa City, Iowa Lines: 55 From article <12902@sybase.sybase.com>, by rhoda@mercury.sybase.com (Rhoda Neimand): > A unix person has just asked me a curious question. I'm kind of puzzled > because I've never thought of doing this before. To me, a far pointer > is a far pointer and a near pointer is a near pointer, period. > > His questions: > > Can you cast a far pointer to a near pointer? My answer is that if you did, > you would lose its "farness", therefore it would no longer point to anything > unless you were sure that its segment address was currently in DS. Is this > correct? Yup. > > Can you cast a near pointer to a far pointer? Not sure here. If you did, Yup. > would the segment address be 0? Does having a segment address of 0 mean Could be. Just as long as FAR:NEAR point to the data. > something special? MAKEINTRESOURCE does something like this. I am actually > confused about the purpose of MAKEINTRESOURCE. Nope. > > I feel that either casting is not meaningful. Is this correct? Nope. If you write in the medium model, pointers are near by default. of you wanna use the Windows calls, they take LPSTR (char far *) pointers in general. Thus, When you do something like: char near *s; . . . SetDlgItemText(win, IDC_CTL, (LPSTR)s); the compiler does the (char far *) cast by pushing the data segment followed by the near char *s pointer. Additionally, if you need to use DLL's, far pointers are much easier to deal with. Thus, a DLL in large model can talk to an app in medium/small models just by casting the near pointers to far and sending those to the DLL. There are many other reasons but this just shows that casting near/far is really used. |----------------------------------------------------------------------------| |Tom Hite | The views expressed by me | |Manager, Product development | are mine, not necessarily | |CADSI (Computer Aided Design Software Inc. | the views of CADSI. | |----------------------------------------------------------------------------|