initialization - What happens to a declared, uninitialized variable in C? Does it have a value? -


If I type in C:

  int num;   

Before I assign anything to num , what is the value of num uncertainty?

Fixed variables (file scope and function constant) are started at zero:

  int x; // zero int y = 0; // also zero zero foo () {static int x; // even zero}  

non-fixed variables (local variables) unsure are defined in the undefined behavior before giving the results of the value.

  void foo () {int x; Printf ("% d", x); // compiler is free to crash here) In practice, they initially have some nonsensical value - some compilers can also put it in specific, fixed values ​​to make it clear. When a debugger is watching - but speaking strictly, the compiler is free to do anything to summon due to crashing. 

Instead, why is this undefined behavior rather than "undefined / arbitrary value"? CPU architecture that has additional flag bits in their representation for different types. A modern example would be; Of course, the standard standard draftster was considering some old architecture.

By attempting to work with a value with these flag bitsets, there can be a CPU exception in an operation which should actually fail (for example, the integer Adding, or specifying another variable) and if you go and leave an uninitialized speed, then the compiler can pick up some random garbage with these flag bits set - meaning that unpublished variables can be fatal.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -