Re: dépassement de mémoire
	
	
		
	Citation:
	
		
		
			
				Envoyé par petdelascar
				
			
			voici le code possiblement responsable:
			
		
	 
 Compile pas...
	Code:
	
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
   |  
../main.c:1: error: syntax error before "allouerMatrice"
../main.c:1: warning: return type defaults to `int'
../main.c:1: warning: no previous prototype for 'allouerMatrice'
../main.c: In function `allouerMatrice':
../main.c:2: error: `Matrice' undeclared (first use in this function)
../main.c:2: error: (Each undeclared identifier is reported only once
../main.c:2: error: for each function it appears in.)
 
../main.c:2: error: syntax error before "A"
../main.c:4: error: `A' undeclared (first use in this function)
../main.c:4: error: syntax error before "sys_malloc"
../main.c:6: error: `COMPLEX' undeclared (first use in this function)
../main.c:6: error: syntax error before ')' token
../main.c:8: error: syntax error before ')' token
../main.c: At top level:
../main.c:13: error: syntax error before "A"
../main.c:13: warning: function declaration isn't a prototype
../main.c: In function `libererMatrice':
../main.c:15: error: `A' undeclared (first use in this function)
../main.c: At top level:
../main.c:20: error: syntax error before "Mat_add"
../main.c:20: error: syntax error before "A"
 
../main.c:20: warning: return type defaults to `int'
../main.c:20: warning: function declaration isn't a prototype
../main.c: In function `Mat_add':
../main.c:22: error: `Matrice' undeclared (first use in this function)
 
../main.c:22: error: syntax error before "C"
../main.c:23: error: implicit declaration of function `deMemeDim'
../main.c:23: warning: nested extern declaration of `deMemeDim'
../main.c:23: error: `A' undeclared (first use in this function)
../main.c:23: error: `B' undeclared (first use in this function)
../main.c:24: error: `Mat_nulle' undeclared (first use in this function)
 
../main.c:24: error: implicit declaration of function `Mat_nulle_quelconque'
../main.c:24: warning: nested extern declaration of `Mat_nulle_quelconque'
../main.c:27: error: `C' undeclared (first use in this function)
../main.c:31: error: implicit declaration of function `AddComplex'
 
../main.c:31: warning: nested extern declaration of `AddComplex'  | 
 Merci de poster du code compilable. On est pas magiciens... 
... un peu quand même... ceci fonctionne :
	Code:
	
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
   |  
#include <stdlib.h>
 
typedef struct
{
   int dummy;
}
COMPLEX;
 
typedef struct
{
   int n;
   int m;
   COMPLEX **P;
}
structMatrice, *Matrice;
 
static int deMemeDim (Matrice A, Matrice B)
{
   return A->n == B->n && A->m == B->m;
}
 
static Matrice Mat_nulle_quelconque (int n, int m)
{
   return NULL;
}
 
static void AddComplex (COMPLEX * pc, COMPLEX * pa, COMPLEX * pb)
{
}
 
/* allouer une matrice de l lignes et c colonnes */
static Matrice allouerMatrice (int l, int c)
{
   Matrice A = malloc (sizeof *A);
   A->n = l;
   A->m = c;
   A->P = malloc (l * sizeof *A->P);
   {
      int i;
      for (i = 0; i < l; i++)
      {
         A->P[i] = malloc (c * sizeof *A->P[i]);
      }
   }
   return A;
}
 
/* libère l'espace mémoire occupé par la matrice */
static void libererMatrice (Matrice A)
{
   if (A != NULL)
   {
      if (A->P != NULL)
      {
         int i;
         for (i = 0; i < A->n; i++)
         {
            free (A->P[i]);
         }
      }
      free (A->P);
   }
   free (A);
}
 
/* renvoie la matrice issue de l'addition de A et de B */
static Matrice Mat_add (Matrice A, Matrice B)
{
   Matrice C = NULL;
 
   if (A != NULL && B != NULL)
   {
      int i, j;
 
      Matrice Mat_nulle;
 
      if (!deMemeDim (A, B))
      {
         Mat_nulle = Mat_nulle_quelconque (A->n, A->m);
         return Mat_nulle;
      }
 
      C = allouerMatrice (A->n, A->m);
 
      for (i = 0; i < A->n; i++)
      {
         for (j = 0; j < A->m; j++)
         {
            //C->P[i][j]=A->P[i][j]+B->P[i][j];
            AddComplex (&C->P[i][j], &A->P[i][j], &B->P[i][j]);
         }
      }
   }
   return C;
}
 
int main (void)
{
   Matrice A = allouerMatrice (2, 3);
 
   if (A != NULL)
   {
      Matrice B = allouerMatrice (2, 4); /* '4' intentionnel */
 
      if (B != NULL)
      {
         Matrice C = Mat_add (A, B);
         libererMatrice (C);
         libererMatrice (B);
      }
      libererMatrice (A);
   }
   return 0;
} |