Re: porting problems encountered

From: navin_2016 (navin_2013_at_yahoo.co.in)
Date: 12/11/03


Date: 10 Dec 2003 20:49:40 -0800

rcbryan@hotmail.com (RC Bryan) wrote in message news:<fbcf38dc.0312090930.2851952@posting.google.com>...
> > > char * sub(char *p)
> > > {
> > > int myP=p;
> > > myP = (myP+15)& 0xfffffff0;/* add and mask back down */
> > > p=(char *)myP;
> > > . . .
> > >
> > >
> > What exactly happens here ? Why are we doing this & 0xffff... ? If we
> > add my+1 then value would be myP + 1*sizeof(myP). Please correct me if
> > i am wrong .
>
> You are wrong. This example is doing integer arithmetic on a pointer
> value. We are adding 15 to myP, an integer, not p, the pointer. If p
> had the value 0x40000F44, by adding 15 (decimal) (or 0xF hex) we get
> 0x40000f53. We then mask off the low order bits to get a 16 byte
> bounded space. 0x40000f53& 0xfffffff0 == 0x40000f50. If we had not
> added 15, we would have 0x40000f40 which is a pointer to a space
> before the start of the p area. (Don't forget C lesson 1, & is bitwise
> and && is logical (the whole variable).) I actually saw this where we
> needed page bounded space which is particularlly not portable. Page
> bounding or 16 byte bounding is the same idea except you can use 511
> and 0xfffffe00 rather than 15 and 0xfffffff0 (on some machines).
>

This may be a silly question. But why are we doing this
myP = (myP+15)& 0xfffffff0;
Why are we adding and masking down . What has "0x40000f40" got to do
with this ? Sorry i don't understand this properly.

Where are all these documented ?. I tried page bounding in google but
hardly found anything useful. I only get results about those
postscript bounding boxes. . Is there any place where i can read more
about all this from.

I understand that you surely need to know assembly if not for coding
at least for debugging.

-