f26p at eircom.net
Thu Feb 11 17:36:04 CET 2010
So you're allowed add an integer to an untyped pointer?!
Usually if you add 1 to a pointer of type t, then sizeof(t) gets added
to the value of the pointer. So if p points at an array of byte, p+1
would point at the next element of the array, 1 byte after p. But if p
points at an array of LongInt, then the next element is 4 bytes on from
p, so adding 1 to p increases p by 4. So what would sizeof(pointer^) be?
To me, adding an integer to an untyped pointer feels undefined (i.e. I
haven't studied the spec for it but I wouldn't have expected the
compiler to do anything sensible with it) because what pointer points to
is undefined and sizeof(something undefined) is not defined. So I
haven't tried that myself.
From your code, I'm guessing that adding 1 to an untyped pointer adds 1
to the address. So ppp + http.header_anz would be http.header_anz bytes
But http.pdata + http.header_anz means to add http.header_anz to a
variable of type pointer to tchararr. That means, imagine http.pdata is
pointing to an array[0..lots] of tcharrarr, find the address of element
http.header_anz of that array. Now, tcharrarr is 1000 bytes long, so I
would expect http.pdata + http.header_anz to be 1000*http.header_anz
bytes after http.pdata.
Is that what you are seeing?
On 11/02/2010 15:38, Rainer Stratmann wrote:
> What is the difference between A* and B*?
> regards, Rainer
> tchararr = array[ 0..999 ] of char;
> pchararr = ^tchararr;
> http_obj = object
> pdata : pchararr;
> header_anz : longint;
> content_anz : longint;
> http : http_obj;
> ppp : pointer;
> // This works for me A*
> ppp := http.pdata;
> ppp := ppp + http.header_anz;
> // This is not working B*
> ppp := http.pdata + http.header_anz;
> write( 'IP-Adress = ' + parse_ip( ppp , http.content_anz ) );
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal