04-14-2009 06:18 AM
In labwindows development 7.1 system, I have created a globe variable A, but I am not inizilization to zero in the program.
My question is the A variable is always zero when I use the globe variable or not?
Is the possible the value is radom base on computer register when I use the globe variable.
any reply I will appreciate. becasue this is urgent confirm issue for us.
We think this globe variable is not inizilizaiton is a bug in the test program, Is right?
Thanks & Best Regards,
Joseph.
04-14-2009 07:20 AM - edited 04-14-2009 07:26 AM
when building using the Debug configuration, your variable is initialized to 0.
when building using the Release configuration, your variable stays uninitialized: its initial value depends on what the memory contained when the application started, which is generally a random garbage.
please note that variable initialization in the Debug configuration is done for convenience and ease of debugging. this behavior is not portable accross compilers: other compiler may not initialize the variable or initialize it to a different specific value.
also, you should not count on any initialization: if your variable needs to be initialized with specific value at program startup, you should explicitely initialize it (by using a constant initializer, e.g. "int A = 42;")
04-14-2009 07:32 AM
Dear dummy_decoy,
Thanks for your quickly reply.
My globe variable is the static int, it's also get the random without inilization in the release mode?
04-14-2009 07:46 AM
Dear dummy_decoy,
Becasue I will use the this static int globe variale to judgement if(!A) in the test program.
So if(!A) this return value should be the random in the release configure. Is this right?
Joseph.
04-14-2009 08:05 AM
In C, static variables are initialised to 0, unless otherwise specified. Local variables are not automatically initialised, except when CVI is compiling in Debug mode.
JR
04-14-2009 08:23 AM
Dear JR,
Thanks for your reply.
And I am confusing with your reply,
Could you help me explain the detail and clearly, what's happen for a globe variable static int without inilization in CVI release mode?
Do you agree dummy_decoy opinions as above reply.
I am confusing between your two people opinions.
I am very appreciate other people join us to discuss to help me claifiy this problem.
Joseph.
04-14-2009 08:54 AM
I think dummy_decoy was referring to local variables (also known as automatic) within a function. He correctly states that these variables are not initialised by the compiler and should therefore be expected to contain a random value. (Unless CVI is in Debug mode, in which case they are initialised to 0. You should not rely on this.)
It is part of the C language definition, that static variables are initialised to 0 by default, unless of course the programmer sets them to this or any other value in the normal way.
So, your global static int in CVI release mode is guaranteed to be set by the compiler to a value of 0.
JR
04-14-2009 09:07 AM
Dear JR,
Thanks for your clearly reply.
And I want to know Do you have any document to explain this case?
and Sent to me by the email : Joseph.zj.han@philips.com
Dear dummy_doecoy,
what's your comment about JR's point?
Joseph.
04-14-2009 10:32 AM
Check out section 3 of this document. Its the nearest (free) thing I could find on the web to a formal language definition - perhaps you will have more time to search than I can spare? If you are after a strictly legal statement you will have to buy a reference book.
JR
04-14-2009 11:58 AM
i was not aware that static variables were initialized to 0. thanks jr_2005 for pointing this to me.
(i think i will definitely buy this standard, i am tired of misinformation because of a lack of a reference document. haaaa, the good old days of Ada...)