Hello guys quick question . why Currency variables are not null when declare them and the Delphi gives some random values?

Hello guys quick question . why Currency variables are not null when declare them and the Delphi gives some random values?

Comments

  1. 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.

    ReplyDelete
  2. FWIW the compiler will tell you "W1036 Variable might not have been initialized"

    Martin Wienold "which can be set to nil zero."

    ReplyDelete
  3. 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.""

    ReplyDelete
  4. Hamza Benzaoui I doubt the bottleneck of any program ever was that variables were being initialized to zero.

    ReplyDelete
  5. 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?

    ReplyDelete

Post a Comment