[fpc-pascal]I don't Understand Array

Gabor DEAK JAHN djg at argus.vki.bke.hu
Fri Feb 16 13:02:21 CET 2001

At 02/16/2001 06:30, you wrote:

Dear Luis,

> When declare a Array variable with character, The compiler add 3 character,
> see the next code :

> var
>    antes:char;
>    m     : array [0..3] of char;
>    despues : char;
> begin
>     Writeln('m[-4] : ',m[-4]);     // variable antes

If you declare a variable with indexes between [m..n], this means that you 
are allowed only to use those indexes when you use the array. In your case, 
m[0], m[1], m[2] and m[3] are the only allowed expressions (or, of course, 
an m[i] where i has a value of 0, 1, 2 or 3). The compiler notifies you with 
the warning 'Range check error while evaluating constants'. Actually, this 
should be labeled an error, not a warning, but its text clearly says: error.

Variables are completely independent. If you declare your antes, then m, 
then despues, you can make no assumptions about where they will be in the 
memory. It is far from certain that antes will be before m, even less 
certain that it will be immediately before it. The compiler is at perfect 
liberty to place these variables in any way it sees fit and for reasons of 
performance, they are usually aligned on multiple byte boundaries, meaning 
that up to a couple of bytes of hole can be between any two variables. This 
is the reason why you see three additional bytes between antes and m, the 
default alignment is at 4-byte boundaries.

If for any reason you want to keep some variables together, knowing their 
exact sequence, location and size, you have to use the device the language 
offers for this purpose, namely, a record (specifying the alignment as 


   Gabor DEAK JAHN

Gabor DEAK JAHN -- Budapest, Hungary.
WWW: <http://www.tramontana.co.hu/>www.tramontana.co.hu
E-mail: djg at tramontana.co.hu

More information about the fpc-pascal mailing list