Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2014-09

Question about local variables initialization

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gennady Agranov

Hi,

I do not have clear picture about initialization of local variables - are they initialized to some default value or not - and is there a way to assure that every local variable (including record types) is set to some default?

Of course the safest approach is to assume that everything is not initialized and filled with garbage.

Is it always true? E.g. is there a way control initialization of record variables on stack?

Thanks,
Gennady

Reply by email

Sven Barth
to Gennady Agranov
"Gennady Agranov" wrote 5 lines
Hi, I do not have clear picture about initialization of local variables - are

they initialized to some default value or not - and is there a way to assure that every local variable (including record types) is set to some default?

Of course the safest approach is to assume that everything is not

initialized and filled with garbage.

Is it always true? E.g. is there a way control initialization of record

variables on stack?

Local variables are not initialized, except managed variables like interfaces, arrays and AFAIK Strings.
You can manually initialize them though like you can global variables (the generated code is however not much different from initializing them yourself inside the function body unlike for global variables).

Regards,
Sven

Reply by email