Currency is a value type, same as Integer, which can not be set to nil. Also, just like Integer, the compiler will not initialize it to zero if it is a local variable.
ok , pretty cool i looked-up and find out why the compiler act like that and found this in C++ community, i guess it's the same reason :
""Because such zero-initializations take execution time. It would make your program significantly slower. Each time you call a function, the program would have to execute pointless overhead code, which sets the variables to zero.
Static variables persist for the whole lifetime of the program, so there you can afford the luxuary to zero-initialize them, because they are only initialized once. While locals are initialized in runtime.
It is not uncommon in realtime systems to enable a compiler option which stops the zero initialization of static storage objects as well. Such an option makes the program non-standard, but also makes it start up faster.""
Stefan Glienke The answer to "Are Delphi variables initialized" is too long now, with too many "If's". It should become either "yes" or "no".
>I'm pretty sure that when we'll do it, we'll >consider only the "initialize with a const >expression" option. As Stefan mentioned, >any other line will be blurred and beg for >further exceptions.
Blurred? Or powerful? Languages like D have compile-time function evaluation for situations like this.
> Imo one should draw the line somewhere
Why do we need a line? Why not simply allow any expression that would be allowed for an already-initialized variable?
Currency is a value type, same as Integer, which can not be set to nil.
ReplyDeleteAlso, just like Integer, the compiler will not initialize it to zero if it is a local variable.
FWIW the compiler will tell you "W1036 Variable might not have been initialized"
ReplyDeleteMartin Wienold "which can be set to nil zero."
ok , pretty cool i looked-up and find out why the compiler act like that and found this in C++ community, i guess it's the same reason :
ReplyDelete""Because such zero-initializations take execution time. It would make your program significantly slower. Each time you call a function, the program would have to execute pointless overhead code, which sets the variables to zero.
Static variables persist for the whole lifetime of the program, so there you can afford the luxuary to zero-initialize them, because they are only initialized once. While locals are initialized in runtime.
It is not uncommon in realtime systems to enable a compiler option which stops the zero initialization of static storage objects as well. Such an option makes the program non-standard, but also makes it start up faster.""
You might want to add your vote to https://quality.embarcadero.com/browse/RSP-14867
ReplyDeleteHamza Benzaoui I doubt the bottleneck of any program ever was that variables were being initialized to zero.
ReplyDeleteStefan Glienke The answer to "Are Delphi variables initialized" is too long now, with too many "If's". It should become either "yes" or "no".
ReplyDelete>I'm pretty sure that when we'll do it, we'll
>consider only the "initialize with a const
>expression" option. As Stefan mentioned,
>any other line will be blurred and beg for
>further exceptions.
Blurred? Or powerful? Languages like D have compile-time function evaluation for situations like this.
> Imo one should draw the line somewhere
Why do we need a line? Why not simply allow any expression that would be allowed for an already-initialized variable?