On 25 Mar 2008, at 14:21, Joao Morais wrote:

Jonas Maebe wrote:
Using uninitialised variables is virtually always bad, regardless of the scope. And the fact that global variables are zeroed at the program start is afaik not defined by the Pascal standard. It's just a side effect of the way most operating systems work.

I think I didn't get your point. What about this piece of code:

interface

function foo: tfoo;

implementation

var
 _foo: tfoo;

function foo: tfoo;
begin
 if not assigned(_foo) then
   _foo := tfoo.create;
 result := _foo;
end;

Is it safe?

It is safe on all currently supported targets (and we even go out of our way to ensure that it keeps working if global variables are turned into register variables), but it's still bad practice (and could in principle break one day, although it's unlikely given the backwards compatibility headaches that would cause).


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to