Re: [fpc-pascal] Pointers

2010-02-12 Thread Frank Peelo

Jonas Maebe wrote:


On 11 Feb 2010, at 18:17, Rainer Stratmann wrote:

In the past with the turbopascal compiler and other always sizeof byte 
was

added.


That is not true. This program prints "2" when compiled under Turbo Pascal:

{$t-}

type
  pw = ^word;
var
  w: pw;
begin
  w:=nil;
  inc(w);
  writeln(longint(w));
end.


i.e. incrementing a pointer to word changes the address by sizeof(word) 
= 2 bytes.


Incrementing always by sizeof(byte) just would not make sense. If you 
have a type that takes more than one byte, such as word, or double, then 
incrementing by sizeof(byte) would take you *inside* the variable, to an 
address where you don't know what you should find! It would depend on 
the endianness of the CPU, and what was in memory after the end of the 
variable, and stuff like that. The only sensible way to increment a 
pointer to SomeType is to increment by sizeof(SomeType). If you really 
want to pick apart a variable byte by byte, use ^Byte.


Frank

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] 2.4.0: Some lines are not compiled (just thrown away)

2010-02-12 Thread Jonas Maebe

On 24 Jan 2010, at 21:10, Gerhard Scholz wrote:

> Some lines are ignored.
> 
> An IF-clause is ignored.
> 
> Versin 2.2.4 runs o.k.

Fixed. Please report bugs at http://bugs.freepascal.org in the future so they 
can't be forgotten.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal