[fpc-pascal] Can variables be declared within a block?
Florian Klaempfl
florian at freepascal.org
Mon Oct 18 15:42:31 CEST 2010
Am 18.10.2010 14:58, schrieb Frank Church:
>
>
> On 18 October 2010 07:49, Florian Klaempfl <florian at freepascal.org
> <mailto:florian at freepascal.org>> wrote:
>
> Am 18.10.2010 08:17, schrieb Zaher Dirkey:
> >
> >
> > On Thu, Oct 14, 2010 at 11:21 AM, Michael Van Canneyt
> > <michael at freepascal.org <mailto:michael at freepascal.org>
> <mailto:michael at freepascal.org <mailto:michael at freepascal.org>>> wrote:
> >
> >
> >
> > On Thu, 14 Oct 2010, Frank Church wrote:
> >
> > Can variables be declared within a begin end block?
> >
> >
> > No.
> >
>
>
> That is a rather emphatic no :).
> Is there some performance or other related reason why it is a bad idea?
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:
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