[Lazarus] Testing Assigned object

Bernd prof7bit at googlemail.com
Tue Apr 26 15:31:44 CEST 2011


2011/4/25 Marco van de Voort <marcov at stack.nl>:
> Initialize it in code not in the declaration, since in the declaration afaik
> that makes it a static variable instead of a truely local one, even when declared
> with local scope.


Hmm...  are you sure?


program project1;

{$mode objfpc}{$H+}


procedure print(num: Integer);
begin
  writeln(num);
end;

procedure foo(cnt: Integer {-4});
var
  x : integer = 0;    {-8}
  y : integer;        {-12}
begin
  print(x);
  print(y);
  inc(x);
  inc(y);
  if cnt < 5 then begin
    foo(cnt + 1);
  end;
end;

begin
  foo(0);
end.

compiled with FPC 2.4.2

P$PROJECT1_FOO$LONGINT:
	pushl	%ebp
	movl	%esp,%ebp
	subl	$12,%esp
	movl	%eax,-4(%ebp)


	movl	TC_P$PROJECT1_FOO$LONGINT_defaultx,%eax
	movl	%eax,-8(%ebp)


	movl	-8(%ebp),%eax
	call	P$PROJECT1_PRINT$LONGINT
	movl	-12(%ebp),%eax
	call	P$PROJECT1_PRINT$LONGINT


	incl	-8(%ebp)
	incl	-12(%ebp)


	movl	-4(%ebp),%eax
	cmpl	$5,%eax
	jl	.Lj23
	jmp	.Lj24
.Lj23:
	movl	-4(%ebp),%eax
	incl	%eax
	call	P$PROJECT1_FOO$LONGINT
.Lj24:
	leave
	ret


output:
0
2
0
134512851
0
134512851
0
134512851
0
134512851
0
134512851




More information about the Lazarus mailing list