#include #include void func(int m, int n, double * restrict a, double * restrict b, double * restrict c); int main(int argc, char*argv[]){ double *a, *b, *c; int i, j, m, n; printf("Please give me m and n: "); scanf("%d%d",&m,&n); if((a=(double*)malloc(m*sizeof(double)))==NULL)perror("memory allocation for a"); if((a=(double*)malloc(m*n*sizeof(double)))==NULL)perror("memory allocation for b"); if((a=(double*)malloc(n*sizeof(double)))==NULL)perror("memory allocation for c"); printf("Initializing matrix M and vector C\n"); for(j=0; j<n; j++) c[j]=2.0; for(i=0; i<m; i++) for(j=0; j<n; j++) b[i*n+j]=i; printf("Executing mxv function for m=%d n=%d\n", m, n); (void) func(m, n, a, b, c);//le variabili diventano restrictedree free(a); free(:trollface:; free(c); return 0;}
Anche, che cavolo serve questa riga?
if((a=(double*)malloc(m*sizeof(double)))==NULL)perror("memory allocation for a");
Oltre ad allocare lo spazio.