È garantito essere 0 se è parzialmente inizializzato, come inizializzatori matrice. Se non è inizializzato, sarà sconosciuto.
struct T t; // t.x, t.y will NOT be initialized to 0 (not guaranteed to)
struct T t = {42}; // t.y will be initialized to 0.
Allo stesso modo:
int x[10]; // Won't be initialized.
int x[10] = {1}; // initialized to {1,0,0,...}
Esempio:
// a.c
struct T { int x, y };
extern void f(void*);
void partialInitialization() {
struct T t = {42};
f(&t);
}
void noInitialization() {
struct T t;
f(&t);
}
// Compile with: gcc -O2 -S a.c
// a.s:
; ...
partialInitialzation:
; ...
; movl $0, -4(%ebp) ;;;; initializes t.y to 0.
; movl $42, -8(%ebp)
; ...
noInitialization:
; ... ; Nothing related to initialization. It just allocates memory on stack.
fonte
2009-04-01 15:25:19
I puntatori verranno inizializzati su NULL correttamente? – user10607