LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Globe variable inizilization problem in the Labwindows development system

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. 

0 Kudos
Message 1 of 11
(4,469 Views)

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;")

Message Edited by dummy_decoy on 04-14-2009 07:26 AM
Message 2 of 11
(4,459 Views)

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? 

0 Kudos
Message 3 of 11
(4,452 Views)

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.

0 Kudos
Message 4 of 11
(4,444 Views)

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

Message 5 of 11
(4,438 Views)

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.

0 Kudos
Message 6 of 11
(4,430 Views)

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

0 Kudos
Message 7 of 11
(4,412 Views)

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.

0 Kudos
Message 8 of 11
(4,408 Views)

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

0 Kudos
Message 9 of 11
(4,395 Views)

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

0 Kudos
Message 10 of 11
(4,383 Views)