Re: porting problems encountered

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


Date: 8 Dec 2003 20:55:26 -0800

rcbryan@hotmail.com (RC Bryan) wrote in message news:<fbcf38dc.0312081556.21378bc3@posting.google.com>...
> char * sub(char *p)
> {
> int myP=p;
> myP = (myP+15)& 0xfffffff0;/* add and mask back down */
> p=(char *)myP;
> . . .
>
> This will break all kinds of places. On 64 bit platforms, the
> pointers are 64 bits while int is 32 bits. It really got interesting
> An example of a bounding problem:
>
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 .

> Using the struct from before:
>
> p=malloc(sizeof(mystruct)*2);
> p+=sizeof(int);
> intVal=((struct MYSTRUCT*)p)->val; /* val is long*/
>
> This will run with a warning on some platforms, crash on others and
>
Is the problem due to assigning of long to int ?

Thanks Bryan for the long post. Most it was useful for me . I have
some doubts in understanding of the code .