[fpc-pascal] Can variables be declared within a block?

Jerry lanceboyle at qwest.net
Tue Oct 19 03:01:19 CEST 2010


On Oct 18, 2010, at 6:42 AM, Florian Klaempfl wrote:

> Am 18.10.2010 14:58, schrieb Frank Church:
> It's just a matter of readability, e.g. having a variable declared in
> two blocks with the same name can cause you a lot of headache:

So don't allow identical names.

Ada allows exactly this feature (declaration within a block) and it is  
extremely simple and not the least confusing. It's also an easy and  
error-free way to manage dynamic memory allocation without using  
pointers.

Jerry

>
> procedure p;
>
> begin
>  ...
>  begin
>    var i : integer;
>    ...
>    ...
>    ...
>    i:=12341234;
>    ...
>    ...
>    ...
>    ...
>  end;
>  ...
>  ...
>  ...
>  begin
>    var i : integer;
>    ...
>    writeln(i); <--- this i is not the same as above so i does not
> contain 12341234 but it contains probably some garbage.
>  end;




More information about the fpc-pascal mailing list