[fpc-pascal] Static local variables available?

Maciej Izak hnb.code at gmail.com
Thu Jul 20 11:11:50 CEST 2017


2017-07-20 11:03 GMT+02:00 Bo Berglund <bo.berglund at gmail.com>:

> So since I don't really want to use a global, is it possible to
> declare a local variable static in the sense that it retains its
> values across calls to the procedure?
> If so how is it done?
>

procedure foo;
{$PUSH}
const{$J+}
  s : string ='';
{$POP}
begin
  writeln(s);
  if s = '' then
    s := 'hello from static local variable';
end;

begin
  foo; // will print empty line
  foo; // will print 'hello from static local variable'
  foo; // will print 'hello from static local variable'
end.

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170720/0abca70d/attachment.html>


More information about the fpc-pascal mailing list