Hello, I had a chance to go to a reference and check on what the reserved word 'nil' , a special constant, seems to mean. According to the Object Pascal manual (Borland) ...
"The reserved word nil is a special constant that can be assigned to any pointer. When nil is assigned to a pointer, the pointer doesn't reference anything." Since a pointer is a memory address value, then the interpretation of the statement "nil +1" would mean for p to point at the very next valid address above the lowest memory address 'p' can hold. So it would appear that 'p := nil + 1' should not compile or work. My guess, and its just a guess, is that for 'nil + 1' to work then it would have to be done in two steps and not one, e.g. 'p := nil; p := p +1; ' .. both of which are valid statements. Now I have no idea what size address increment the compiler would choose (byte, word, float, etc.) to add to p. Perhaps it assumes PChar .. But if that's not how it works, then my next question about the interpretation of 'p := nil + 1; ' is what is the 'size' of the 'p + 1' increment? How can that increment be set to without casting 'p' to a specific Pascal type (Integer, Char, Byte, Word, etc.). So for Object Pascal the side effect of the statement 'p := nil +1' has to be valid address. As such the compiler does not know the type of object 'p' points at, it can't create a valid address. On the other hand, untyped Pointers are a compromise in Object Pascal , a strongly typed language, to be similar to untyped pointer expressions like void * pointers in "C". Untyped C language pointers, according to K&R, represent the smallest unit of addressable memory for the CPU architecture (bytes on Intel). However, even in C, the closest equivalent expression to 'p := nil + 1', void *p, is 'p = NULL, p = p + 1' works (compiles) but issues a warning about the 'p = p + 1' expression (GCC v4). On Mon, May 25, 2009 at 12:48 PM, Prince Riley <wmarketi...@gmail.com>wrote: > Hello, > > There seems to be a bigger issue on this... but perhaps someone else > confirm that the following programs, similar to the failing one, work. > > program test1; > var > p: Pointer; > begin > p := nil; > p := p + 1; > end. > > Does work .... and the following program > > program test2; > var > p: Pointer; > begin > p := nil; > Inc(p); > end. > > works also .... am I the only one getting this result? > > Prince > > > > On Sun, May 24, 2009 at 4:30 PM, Joost van der Sluis <jo...@cnoc.nl>wrote: > >> Op zondag 24-05-2009 om 23:14 uur [tijdzone +0200], schreef Aleksa >> Todorovic: >> > Hi, all! >> > >> > I've just tried to compile some of my old Pascal code, and got IE >> > 200307043. I've tried both 2.2.4 and svn trunk versions. Simple >> > program to generate it: >> > >> > program test; >> > var >> > p: Pointer; >> > begin >> > p := nil + 1; >> > end. >> > >> > I couldn't find issue about this in bug tracker, should I report it? >> >> Yes, an IE is always a bug an should be reported. If you can not a >> report with '200307043' in it, it's not reported yet. >> >> Joost. >> >> >> _______________________________________________ >> fpc-pascal maillist - fpc-pascal@lists.freepascal.org >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> > >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal