Thread overview
Comparing Huge Pointers
Jun 22, 2001
Mark Evans
Jun 22, 2001
Walter
Jun 22, 2001
Mark Evans
Jun 22, 2001
Walter
Jun 22, 2001
Mark Evans
Jun 22, 2001
Walter
June 22, 2001
There is an include file called HUGEPTR.H which for some reason is not in the win16 subfolder.  (Contents appended below.)

I just want to ask whether this is the "approved" method of comparing and differencing huge pointers under Win16.  I need the ability to compute logical relations and distances between pointers.

Mark

=======================================================================

/* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.1 $ */
#if __SC__ || __RCC__
#pragma once
#endif

#ifndef __HUGEPTR_H
#define __HUGEPTR_H 1

#if __cplusplus
extern "C" {
#endif

#if __INTSIZE == 4

#define hugeptr_cmp(h1,h2) ((h1) - (h2))
#define hugeptr_diff(h1,h2) ((h1) - (h2))
#define hugeptr_add(h1,offset) ((h1) + (offset))

#else

long __pascal hugeptr_diff(void __far *h1,void __far *h2);
void __far * __pascal hugeptr_add(void __far *h1,long offset);

#define hugeptr_cmp(h1,h2) ((long)(h1) - (long)(h2))
#define hugeptr_diff(h1,h2) (hugeptr_diff((h1),(h2)) / sizeof(*h1))
#define hugeptr_add(h,offset) (hugeptr_add(h,(long)offset * sizeof(*h)))

#endif

#if __cplusplus
}
#endif

#endif


June 22, 2001
It should work fine for win16, dos16, and 286 extended dos. -Walter

Mark Evans wrote in message <1103_993231465@evans>...
>There is an include file called HUGEPTR.H which for some reason is not in
the win16 subfolder.  (Contents appended below.)
>
>I just want to ask whether this is the "approved" method of comparing and
differencing huge pointers under Win16.  I need the ability to compute logical relations and distances between
>pointers.
>
>Mark
>
>=======================================================================
>
>/* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.1 $ */
>#if __SC__ || __RCC__
>#pragma once
>#endif
>
>#ifndef __HUGEPTR_H
>#define __HUGEPTR_H 1
>
>#if __cplusplus
>extern "C" {
>#endif
>
>#if __INTSIZE == 4
>
>#define hugeptr_cmp(h1,h2) ((h1) - (h2))
>#define hugeptr_diff(h1,h2) ((h1) - (h2))
>#define hugeptr_add(h1,offset) ((h1) + (offset))
>
>#else
>
>long __pascal hugeptr_diff(void __far *h1,void __far *h2);
>void __far * __pascal hugeptr_add(void __far *h1,long offset);
>
>#define hugeptr_cmp(h1,h2) ((long)(h1) - (long)(h2))
>#define hugeptr_diff(h1,h2) (hugeptr_diff((h1),(h2)) / sizeof(*h1))
>#define hugeptr_add(h,offset) (hugeptr_add(h,(long)offset * sizeof(*h)))
>
>#endif
>
>#if __cplusplus
>}
>#endif
>
>#endif
>
>


June 22, 2001
Walter,

Which huge-pointer functions are mandatory, and when can I just use normal C pointer arithmetic.  For example can I do things like the following across segment boundaries:

char __huge *ptr;
char __huge *buf;
long int i;

buf = _halloc(200000,1); // multiple segment crossings in the buffer
ptr = buf + 50000; // point anywhere in the buffer using normal pointer arithmetic, no hptr_add
for(i=0;i<(64000*2);i++)
{
    *ptr++ = 'C'; // normal pointer incrementing, no use of hptr_add, may cross segment boundaries
}


My impression is that I can, unless I want to actually compare two huge pointers -- in which case hugeptr_diff or hugeptr_cmp would be mandatory.  So the only truly mandatory functions would be the comparison/difference functions, correct?  Under Win16, the preprocessor variable __INTSIZE == 2, so the second header clause applies.

Thanks,

Mark


On Fri, 22 Jun 2001 12:55:03 -0700, "Walter" <walter@digitalmars.com> wrote:
> It should work fine for win16, dos16, and 286 extended dos. -Walter
> 
> Mark Evans wrote in message <1103_993231465@evans>...
> >There is an include file called HUGEPTR.H which for some reason is not in
> the win16 subfolder.  (Contents appended below.)
> >
> >I just want to ask whether this is the "approved" method of comparing and
> differencing huge pointers under Win16.  I need the ability to compute logical relations and distances between
> >pointers.
> >
> >Mark
> >
> >=======================================================================
> >
> >/* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.1 $ */
> >#if __SC__ || __RCC__
> >#pragma once
> >#endif
> >
> >#ifndef __HUGEPTR_H
> >#define __HUGEPTR_H 1
> >
> >#if __cplusplus
> >extern "C" {
> >#endif
> >
> >#if __INTSIZE == 4
> >
> >#define hugeptr_cmp(h1,h2) ((h1) - (h2))
> >#define hugeptr_diff(h1,h2) ((h1) - (h2))
> >#define hugeptr_add(h1,offset) ((h1) + (offset))
> >
> >#else
> >
> >long __pascal hugeptr_diff(void __far *h1,void __far *h2);
> >void __far * __pascal hugeptr_add(void __far *h1,long offset);
> >
> >#define hugeptr_cmp(h1,h2) ((long)(h1) - (long)(h2))
> >#define hugeptr_diff(h1,h2) (hugeptr_diff((h1),(h2)) / sizeof(*h1))
> >#define hugeptr_add(h,offset) (hugeptr_add(h,(long)offset * sizeof(*h)))
> >
> >#endif
> >
> >#if __cplusplus
> >}
> >#endif
> >
> >#endif
> >
> >
> 
> 


June 22, 2001
Yes, that code should work. The hugeptr.h was there before it was added to the compiler, and was retained for backwards compatibility.

What wasn't done was creating an entire 'huge' memory model with runtime library, etc.

Mark Evans wrote in message <1103_993238062@evans>...
>Walter,
>
>Which huge-pointer functions are mandatory, and when can I just use normal
C pointer arithmetic.  For example can I do things like the following across segment boundaries:
>
>char __huge *ptr;
>char __huge *buf;
>long int i;
>
>buf = _halloc(200000,1); // multiple segment crossings in the buffer ptr = buf + 50000; // point anywhere in the buffer using normal pointer
arithmetic, no hptr_add
>for(i=0;i<(64000*2);i++)
>{
>    *ptr++ = 'C'; // normal pointer incrementing, no use of hptr_add, may
cross segment boundaries
>}
>
>
>My impression is that I can, unless I want to actually compare two huge
pointers -- in which case hugeptr_diff or hugeptr_cmp would be mandatory. So the only truly mandatory functions would
>be the comparison/difference functions, correct?  Under Win16, the
preprocessor variable __INTSIZE == 2, so the second header clause applies.
>
>Thanks,
>
>Mark
>
>
>On Fri, 22 Jun 2001 12:55:03 -0700, "Walter" <walter@digitalmars.com>
wrote:
>> It should work fine for win16, dos16, and 286 extended dos. -Walter
>>
>> Mark Evans wrote in message <1103_993231465@evans>...
>> >There is an include file called HUGEPTR.H which for some reason is not
in
>> the win16 subfolder.  (Contents appended below.)
>> >
>> >I just want to ask whether this is the "approved" method of comparing
and
>> differencing huge pointers under Win16.  I need the ability to compute logical relations and distances between
>> >pointers.
>> >
>> >Mark
>> >
>> >=======================================================================
>> >
>> >/* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.1 $ */
>> >#if __SC__ || __RCC__
>> >#pragma once
>> >#endif
>> >
>> >#ifndef __HUGEPTR_H
>> >#define __HUGEPTR_H 1
>> >
>> >#if __cplusplus
>> >extern "C" {
>> >#endif
>> >
>> >#if __INTSIZE == 4
>> >
>> >#define hugeptr_cmp(h1,h2) ((h1) - (h2))
>> >#define hugeptr_diff(h1,h2) ((h1) - (h2))
>> >#define hugeptr_add(h1,offset) ((h1) + (offset))
>> >
>> >#else
>> >
>> >long __pascal hugeptr_diff(void __far *h1,void __far *h2);
>> >void __far * __pascal hugeptr_add(void __far *h1,long offset);
>> >
>> >#define hugeptr_cmp(h1,h2) ((long)(h1) - (long)(h2))
>> >#define hugeptr_diff(h1,h2) (hugeptr_diff((h1),(h2)) / sizeof(*h1))
>> >#define hugeptr_add(h,offset) (hugeptr_add(h,(long)offset * sizeof(*h)))
>> >
>> >#endif
>> >
>> >#if __cplusplus
>> >}
>> >#endif
>> >
>> >#endif
>> >
>> >
>>
>>
>
>


June 22, 2001
Good, I thought so.  In that case, do I still need hugeptr_diff() and hugeptr_cmp(), or can I just use the minus sign as I would in 32-bit C?  For example would this work:

char __huge *buf;
char __huge *ptrA;
char __huge *ptrB;
signed long int diff;

buf = _halloc(200000,1);
ptrA = buf + 80000;
ptrB = buf + 120000;
diff = ptrB - ptrA;
printf("The difference is %ld.\n",diff); // should be 40000


I may not need to include HUGEPTR.H at all if the above works OK.

(I do understand completely about the memory model issue and am not asking for that.)

Thanks,

Mark


On Fri, 22 Jun 2001 15:35:36 -0700, "Walter" <walter@digitalmars.com> wrote:
> Yes, that code should work. The hugeptr.h was there before it was added to the compiler, and was retained for backwards compatibility.
> 
> What wasn't done was creating an entire 'huge' memory model with runtime library, etc.
> 


June 22, 2001
It should work fine. If you wish to verify it, just write a small stub, compile it, and obj2asm the result. -Walter

Mark Evans wrote in message <1104_993246193@evans>...
>Good, I thought so.  In that case, do I still need hugeptr_diff() and
hugeptr_cmp(), or can I just use the minus sign as I would in 32-bit C?  For
example would this work:
>
>char __huge *buf;
>char __huge *ptrA;
>char __huge *ptrB;
>signed long int diff;
>
>buf = _halloc(200000,1);
>ptrA = buf + 80000;
>ptrB = buf + 120000;
>diff = ptrB - ptrA;
>printf("The difference is %ld.\n",diff); // should be 40000
>
>
>I may not need to include HUGEPTR.H at all if the above works OK.
>
>(I do understand completely about the memory model issue and am not asking
for that.)
>
>Thanks,
>
>Mark
>
>
>On Fri, 22 Jun 2001 15:35:36 -0700, "Walter" <walter@digitalmars.com>
wrote:
>> Yes, that code should work. The hugeptr.h was there before it was added
to
>> the compiler, and was retained for backwards compatibility.
>>
>> What wasn't done was creating an entire 'huge' memory model with runtime library, etc.
>>
>
>