RDV+DIAL chat illimit� dans ta r�g!
no save
Assistance
Achat
News

Forum | programmation
[C] erreur de segmentation
mamiemando, le mer. 22 nov. 2006 à 01:02:24
Celà signifie que tu accède à une zone mémoire non allouée (erreur typique en C quand on commence à manipuler des pointeurs ou des tableaux).

Exemple :

#include <stdio.h>

int main(){
int tab[5];
printf("%d\n",tab[69]); //seg fault car tab[69] est hors du tableau
int *x;
*x = 28; // seg fault, car *x est un entier non alloué
return 0;
}
Solution :
#include <stdio.h>
#include <stdlib.h>

int main(){
int tab[70];
printf("%d\n",tab[69]);
int *x =(int*)malloc(sizeof(int));
*x = 28;
return 0;
}
Comment détecter une segmentation fault avec gcc+gdb :
gcc -g -W -Wall -o plop.exe plop.c
gdb plop.exe
Dans gdb :
r
bt
A noter que pour windows dev cpp est basé sur gcc...

Bonne chance
Précédenttophe03
nov. 06
tophe03
nov. 06
Suivant
REPONSES
mamiemando
nov. 06
tophe03
nov. 06
mamiemando
nov. 06
Char Snipeur
nov. 06
tophe03
nov. 06
mamiemando
nov. 06
Char Snipeur
nov. 06
tophe03
nov. 06
Version Web
Réalisé par RedShift
no save