Jump to content

Undefined values: Difference between revisions

Updated D entry
(Updated D entry)
Line 173:
=={{header|D}}==
In D variables are initialized either with an explicit Initializer or are set to the default value for the type of the variable. If the Initializer is void, however, the variable is not initialized. If its value is used before it is set, undefined program behavior will result. "void" initializers can be used to avoid the overhead of default initialization in performance critical code.
<lang d>//void initializedmain() {
// Initialized:
int a = 5;
double b int a = 5.0;
char c double b = 'f'5.0;
char c = 'f';
int[] d = [1, 2, 3];
 
// defaultDefault initialized:
int aa; // set to 0
double bb; // set to double.naninit, that is a NaN
char cc; // set to 0xFF
int[] dd; // set to null
int[3] ee; // set to [0, 0, 0]
 
// Undefined (contain garbage):
// undefined
int aaa = void; //int assert(aaa != 0)void;
double[] bbb = void; // assert(bbb !is null)
int[3] eee = void; // contains garbage</lang>
}</lang>
 
=={{header|Delphi}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.