ingframin
03-06-2016, 22:01
Buona sera,
stavo vedendo dei video su youtube e in uno di questi il tipo fa questo esempio:
struct Data{
char buffer[100];
};
struct Data func(){
struct Data d;
strcpy(d.buffer,"stringa che non ricordo",100);
return d;
}
E a seguito di questo esempio dice che tutto l'array verrà restituito sullo stack...
Secondo me invece, in cima allo stack resterà una struttura che contiene il puntatore al buffer;
Perché l'intero array dovrebbe restare sullo stack? È per via del fatto che dichiara la struttura nella funzione?
Poi... se fa strcpy su un array non inizializzato, non ha un segmentation fault?
:confused:
stavo vedendo dei video su youtube e in uno di questi il tipo fa questo esempio:
struct Data{
char buffer[100];
};
struct Data func(){
struct Data d;
strcpy(d.buffer,"stringa che non ricordo",100);
return d;
}
E a seguito di questo esempio dice che tutto l'array verrà restituito sullo stack...
Secondo me invece, in cima allo stack resterà una struttura che contiene il puntatore al buffer;
Perché l'intero array dovrebbe restare sullo stack? È per via del fatto che dichiara la struttura nella funzione?
Poi... se fa strcpy su un array non inizializzato, non ha un segmentation fault?
:confused: