0

Debugging I have an error at run time in this function:

void pre_filter_Computations(double **radius,double **theta,int cols,int rows){

double x[cols],y[rows];
double X[cols][rows], Y[cols][rows];
double epsilon=0.0001;

 printf("Entering prefilter function\n");

 for(int i=0;i<cols*2;i++){
    x[i]=((double)(i-cols)/2/((double)cols/2;
 }
 ...

I had to change this for loop. Before changing it running the project it enter and exit the function. But for an error in the loop, I had to change it and another similar. When I run again I can t enter the function. Debugging I have a Suspended Signal SIGSEGV : Segmantation Fault before entering the function at print line!

About theta and radius:

double** radius, **theta;

raidus=(double**)malloc(sizeof(double*)*rows);
 for(int i=0;i<rows;i++);
  radius[i]=(double*)malloc(sizeof(double)*cols);

theta=(double**)malloc(sizeof(double*)*rows);
 for(int z=0;z<rows;z++);
  theta[z]=(double*)malloc(sizeof(double)*cols);

Someone understand where is the error?

  • 4
    You have `;`'s after the for-loops that shouldn't be there and missing `)`'s after the `malloc`'s, though these would cause compile-time errors (in this case, given the code provided) and would thus be unrelated to your problem. Please copy-and-paste code rather than rewriting it to avoid these issues in future. – Bernhard Barker Jun 28 '13 at 13:19
  • 1
    I haven't tried something like this before, but wouldn't simply this work: `double (*radius)[rows] = new double[cols][rows];` (instead of your overcomplicated `malloc`'s)? And the casting of `malloc`'s return value is unnecessary, and you should use `new` and `delete` in C++, not `malloc` and `free`. – Bernhard Barker Jun 28 '13 at 13:25
  • Hi, I edited again. I just copy the code bad, because I work with VM. And I can t use internet in the VM where I work. In our univeristy we just studied C and not C++. In C the correct way is to use malloc. So as you say I have just to change this 3 lines with: double (*radius)[rows] = new double[cols][rows]; – Elvio Esposito Jun 28 '13 at 13:38
  • Actually, in that case you'll need to change the function parameter to `int (*radius)[rows]`, which will require that `rows` be a hard-coded value, which may not be desired, see [this](http://stackoverflow.com/questions/720707/how-to-return-two-dimensional-char-array-c) for better ways of doing it. – Bernhard Barker Jun 28 '13 at 13:47
  • `double **radius=new radius*[rows]; for (int i=0; i – Elvio Esposito Jun 28 '13 at 14:06
  • I probably results in the same behaviour, but [you should use `new` instead of `malloc` in C++](http://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-vs-new/). It probably won't fix your problem, that's why it's a comment and not an answer. – Bernhard Barker Jul 01 '13 at 08:14

0 Answers0