Are global variables in Pascal Script zero-initialized?

 ̄綄美尐妖づ 提交于 2019-12-23 05:07:35

问题


When I declare a global variable in [Code] section (Pascal Script) of Inno Setup script, is it automatically initialized to zero/empty value? Or do I have to explicitly initialize it (e.g. in InitializeSetup event function)?

var
  GlobalNumber: Integer;

function InitializeSetup(): Boolean;
begin
  { Is this necessary? }
  GlobalNumber := 0;

  Result := True;
end;

From my experience, the variables are zero-initialized. Though, I'm not sure if I just have not been lucky.

I've done 10.000 iterations of a test code. The global variables (or various types, integer, string, pointer) were always zero-initialized.


回答1:


Variables are automatically initialized in Pascal Script afaik.

I thought that I also read this in earlier times somewhere in the docs, but I could not find a clear statement in documentation again. However, if you look at the examples from Pascal Script's official manual, variables are also not always initialized there. In the first code on this page for example, strings are added to Messages without having it initialized before.



来源:https://stackoverflow.com/questions/34015970/are-global-variables-in-pascal-script-zero-initialized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!