[comp.sys.ibm.pc] Segment & offset of pointers in MS C v4.0

arden@creed.tcom.stc.co.uk (Bruce Arden) (03/17/87)

I want to have two macros P_SEG(p) and P_OFF(p) (cf FP_SEG & 
FP_OFF) that will let me get the segment and offset of p 
independant of the memory model.  Here is an example of their
intended use: 

    char scr[SCRSIZE];

    movedata(0xB000, 0x0000, P_SEG(scr), P_OFF(scr), sizeof scr);

I thought I had the answer to this question:

#define P_SEG(p)    (unsigned)((long)( (char far *)(p) ) >> 16)
#define P_OFF(p)    (unsigned)((long)( (char far *)(p) ))

This appeared to give the correct result (although it did 
generate some redundant code) with data pointers.  However it 
gave register DS as the segment of a near code pointer.

Has anyone solved this problem?

Thanks in advance
-- 
Bruce Arden
arden@creed.tcom.stc.co.uk

mouse@mcgill-vision.UUCP (03/24/87)

In article <247@creed.tcom.stc.co.uk>, arden@creed.tcom.stc.co.uk (Bruce Arden) writes:
> #define P_SEG(p)    (unsigned)((long)( (char far *)(p) ) >> 16)
> #define P_OFF(p)    (unsigned)((long)( (char far *)(p) ))

> This appeared to give the correct result (although it did generate
> some redundant code) with data pointers.  However it gave register DS
> as the segment of a near code pointer.

I don't know the particular compiler, but I'm not surprised.  After
all, you *are* casting it to a data pointer!  Try something like

#define CODEP_SEG(p)    (unsigned)((long)( (int (far *)())(p) ) >> 16)
#define CODEP_OFF(p)    (unsigned)((long)( (int (far *)())(p) ))

for code pointers.

					der Mouse

Smart mailers: mouse@mcgill-vision.uucp
USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!musocs!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu

srp@ethz.UUCP (03/29/87)

In article <703@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP writes:
>
>					der Mouse

	Shouldn't that be "die Maus" ?
-- 
-----------

Scott Presnell  Swiss Federal Institute of Technology (ETH-Zentrum)
		Department of Organic Chemistry
		Universitaetsstrasse 16
		CH-8092 Zurich Switzerland.

uucp:		...seismo!mcvax!cernvax!ethz!srp     (srp@ethz.uucp)
earn/bitnet:	Benner@CZHETH5A