|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Feb 2007
Città: Imperia "S.S.28"
Messaggi: 905
|
[C++] Char[n] e *Char HELP
Allora io dichiaro una variabile buffer
char buffer[100]; Una funzione è così definita bool FAI(char *dati) Ovviamente se faccio FAI(buffer) da errore in compilazione... ma è corretto fare un cast così FAI( (char*) buffer) in questo modo compila... Mi spiegate ciò? grazie... In pratica con char buffer[100] alloco la memoria, mentre dichiarando char *buffer; non alloco la memoria creo solo un puntatore: se poi vado ad utilizzare la memcpy nel primo caso funziona nel secondo caso scrivo in pezzi di memoria non allocata e quindi si può piantare giusto??????
__________________
Dont drink and drive but smoke and fly Peugeot 206 enfant terrible!!! |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2006
Città: Roma
Messaggi: 1383
|
veramente a me questo programma non da il minimo errore in compilazione, poi forse ho capito male:
Codice:
char buffer[100];
bool FAI(char *dati) {
return true;
}
int main() {
FAI(buffer);
return 0;
}
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Feb 2007
Città: Imperia "S.S.28"
Messaggi: 905
|
Ops neanche a me.....
L'errore si presenta se dichiari buffer come unsigned char, che poi non ne capisco il senso visto che char è un byte e anche unsigned char è un byte. Grazie per avermi fatto capire che dipendeva da ciò!!!
__________________
Dont drink and drive but smoke and fly Peugeot 206 enfant terrible!!! |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:21.



















