Reference to an un-initialized variable in release build in VC6/VC

G

Guest

Can anyone talk me is there existed a "default" value for a un-initialized
int variable in a release build in VC6 and VC7.1. (I know there is a
compilation warning)

For Example:
main(){
int a;
printf("variable 'a' is un-initialized and its value is = %d\n", a);
}
I want to know whether the compiler will assign a "default" value to
variable 'a' during the release building and the behaviour are the same
between VC6 and VC7.1?

Thanks and regards,
lauch2.
 
M

Mike P

lauch2 said:
Can anyone talk me is there existed a "default" value for a un-initialized
int variable in a release build in VC6 and VC7.1. (I know there is a
compilation warning)

For Example:
main(){
int a;
printf("variable 'a' is un-initialized and its value is = %d\n", a);
}
I want to know whether the compiler will assign a "default" value to
variable 'a' during the release building and the behaviour are the same
between VC6 and VC7.1?

Thanks and regards,
lauch2.

As far as I known, neither VC6 or VC7.1 do any initializtion on variables in
release mode. You get a random value. That being said, in my opinion, all
variables should be initialized. Always. I've seen lots of subtle (and not
so subtle) failures caused by unitilized variables. Always initialize ---
it'll save you grief in the long run.

Mike P
 
G

Guest

As far as I known, neither VC6 or VC7.1 do any initializtion on variables in
release mode. You get a random value. That being said, in my opinion, all
variables should be initialized. Always. I've seen lots of subtle (and not
so subtle) failures caused by unitilized variables. Always initialize ---
it'll save you grief in the long run.

Mike P

Thanks Mike, I totally agree with you and I have experienced some unexpected
exception due to the un-initialized variable. I am posting the question just
becuase I right now need to migrate someone's code to VC7.1 and find some
variables had not been initialized before refering them. It seems the
behaviour for un-initialized variable has been changed in VC7.1.

Further comment on this issue are appreciated!

Thanks in advance,
lauch2
 
J

Jochen Kalmbach [MVP]

Hi lauch2!
Thanks Mike, I totally agree with you and I have experienced some unexpected
exception due to the un-initialized variable. I am posting the question just
becuase I right now need to migrate someone's code to VC7.1 and find some
variables had not been initialized before refering them. It seems the
behaviour for un-initialized variable has been changed in VC7.1.

AFAIK the behaviour has not been changed... the only thing which was
changed, is that the compiler will generate a warning if a variable is
used without initialization.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top