Seg Fault on 2nd Pass

M

Matt

Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
....

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read.
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I'm just after some ideas regarding how this is possible?

Kind Regards,

Matt
 
F

Fred Kleinschmidt

Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read.
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I'm just after some ideas regarding how this is possible?

Something else you are doing later in the loop is causing the problem,
probably clobbering stamps or its members.
Show the whole code.
 
B

Ben Bacarisse

Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I'm just after some ideas regarding how this is possible?

The most likely reason is simply that some code in the loop is messing
up you program's data. For example, undefined access though a rouge
pointer could change 'stamps' so that stamps[1] becomes invalid as
triggers the fault. The real problem is almost always somewhere else.

If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!
 
M

Matt

Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:
for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...
Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.
Therefore, I'm just after some ideas regarding how this is possible?

The most likely reason is simply that some code in the loop is messing
up you program's data. For example, undefined access though a rouge
pointer could change 'stamps' so that stamps[1] becomes invalid as
triggers the fault. The real problem is almost always somewhere else.

If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!

Rhe smal testable pieces are in the many seperate source files I have.
Sadly they are all heavily inter-dependant and many lines o fcode are
executed in the main function before this particular function is
reached. If it is of any use, I've posted the FOR loop in its entirety
below so you can see if there are any changes, though I should note
that the only relevant one I can find is "stamps.norm = sum;" b ut
this is changing a different sub-structure to scprod.

I've commented the GSL parts so it is clear what each part is doing.

for( i = 0 ; i < stamp_number ; i++ )

{

printf("%g\n",stamps[1].scprod[2]); /* SEGMENTATION FAULT HERE ON
2ND PASS FROM i DO LOOP */

for( im = 1 ; im <= ncomps ; im++ )

{

gsl_vector_set( check_vec , im , stamps.scprod[im] ); /* Sets
check_vec[im] = stamps.scprod[im] */

for( jm = 1 ; jm <= im ; jm++ )

{

gsl_matrix_set( check_mat , im , jm , stamps.mat[im]
[jm] ); /* Sets check_mat[im][jm] = stamps.mat[im][jm] */

}

}

gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , ncomp_total + 1 + 100 , ncomp_total + 1 + 100 ); /*
Create a vector view */
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , ncomp_total + 1 + 100 ); /* Create a matrix view */

gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d ); /*
Factorise square matrix check_mat_view into LU decomposition PA=LU */

gsl_linalg_LU_svx( &check_mat_view.matrix , indx ,
&check_vec_view.vector ); /* Solve the square system */

for( j = 0 , sum = 0.0 ; j < ncomp_kernel ; j++ )

{

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j]; /*
Read check_vec[j+1] */

}

check_stack = sum;
stamps.norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps.x , stamps.y , sum );

}


Kind Regards,

Matt
 
B

Ben Bacarisse

Matt said:
Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:
for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...
Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault
The most likely reason is simply that some code in the loop is messing
up you program's data.
If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!
Rhe smal testable pieces are in the many seperate source files I have.
Sadly they are all heavily inter-dependant and many lines o fcode are
executed in the main function before this particular function is
reached. If it is of any use, I've posted the FOR loop in its entirety
below so you can see if there are any changes, though I should note
that the only relevant one I can find is "stamps.norm = sum;" b ut
this is changing a different sub-structure to scprod.


C does not works like that. Any one of the gsl_* functions could be
messing up your data if it is passed the wrong stuff. Even the line
'check_stack = sum;' could be at fault depending on the definition
of check_stack. You probably know this. The important point is that
debugging requires fanatical skepticism -- everything is in doubt
until you are sure about it.

How to move forward? You should try to cut down the code. Without
knowing the problem domain, I can't say how much sense this makes, but
removing chucks of the loop might let you find the problem.

You should consider using compile options like -fmudflap (if you are
using gcc) and tools like valgrind. Even configuring malloc to check
for some errors might help.

Also, I note that there is a lively help list for gsl[2], but try
really hard to make a cut-down example. They will want one as much as
we do! BTW, if *have* to post a code fragment, always include at
least the declarations of the main variables involved.

<code snipped>

[1] MALLOC_CHECK_=2 with most gcc libraries.
[2] http://lists.gnu.org/archive/html/help-gsl/
 
M

Matt

Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:
for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...
Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault
The most likely reason is simply that some code in the loop is messing
up you program's data.
If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!
Rhe smal testable pieces are in the many seperate source files I have.
Sadly they are all heavily inter-dependant and many lines o fcode are
executed in the main function before this particular function is
reached. If it is of any use, I've posted the FOR loop in its entirety
below so you can see if there are any changes, though I should note
that the only relevant one I can find is "stamps.norm = sum;" b ut
this is changing a different sub-structure to scprod.


C does not works like that. Any one of the gsl_* functions could be
messing up your data if it is passed the wrong stuff. Even the line
'check_stack = sum;' could be at fault depending on the definition
of check_stack. You probably know this. The important point is that
debugging requires fanatical skepticism -- everything is in doubt
until you are sure about it.

How to move forward? You should try to cut down the code. Without
knowing the problem domain, I can't say how much sense this makes, but
removing chucks of the loop might let you find the problem.

You should consider using compile options like -fmudflap (if you are
using gcc) and tools like valgrind. Even configuring malloc to check
for some errors might help.

Also, I note that there is a lively help list for gsl[2], but try
really hard to make a cut-down example. They will want one as much as
we do! BTW, if *have* to post a code fragment, always include at
least the declarations of the main variables involved.

<code snipped>

[1] MALLOC_CHECK_=2 with most gcc libraries.
[2]http://lists.gnu.org/archive/html/help-gsl/


Thanks for the reply.

As requested, here is the section of the code in question. It will
compile, but it is now seg faulting on the first attempt I make to
assign a value to stamps[1].scprod[2]. I'm assuming there is a link
between this and the actual problem.

/* A programme to test a seg fault error I'm getting */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>

typedef struct

{
int x , y;
double **vectors;
double *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;

stamp_struct *stamps;

int main()

{

int i,j;
int im, jm;
int d;

double mean, sigma, sum, *sum_vectors, *check_stack;

stamps = (stamp_struct *)malloc( 196 * sizeof(stamp_struct) );

stamps.scprod = (double *)malloc( 55 * sizeof(double) );

gsl_permutation * indx = gsl_permutation_calloc( 425 );

mean = sigma = 0.0;

printf("Seg_Fault_Test.c: Matrix 'check_mat' declared with size %d
\n" , 425 );
gsl_matrix *check_mat = gsl_matrix_calloc( 425 , 425 );

printf("Seg_Fault_Test.c: Matrix 'check_vec' declared with size %d
\n" , 425 );
gsl_vector *check_vec = gsl_vector_calloc( 425 );

stamps[1].scprod[2] = 10.0;

for( i = 0 ; i < 96 ; i++ )

{

printf("Seg_Fault_Test.c: Begin Pass %d\n",i);

printf("%g\n",stamps[1].scprod[2]); /* SEGMENTATION FAULT HERE ON
2ND PASS FROM i DO LOOP */

printf("Seg_Fault_Test.c: Statement printed successfully\n");

for( im = 1 ; im <= 54 ; im++ )

{

gsl_vector_set( check_vec , im , stamps.scprod[im] );

for( jm = 1 ; jm <= im ; jm++ )

{

gsl_matrix_set( check_mat , im , jm , stamps.mat[im][jm] );

}

}

gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , 425 , 425 );
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , 425 );

gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d );

gsl_linalg_LU_svx( &check_mat_view.matrix , indx ,
&check_vec_view.vector );

for( j = 0 , sum = 0.0 ; j < 53 ; j++ )

{

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

}

check_stack = sum;
stamps.norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps.x , stamps.y , sum );

}

return 0;

}





Kind Regards,

Matt
 
R

Richard Tobin

Matt said:
Hello. I'm after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read.

Run your program under a debugger. Set a breakpoint at the printf
line. When it stops there, set it to stop when the value of
stamps[1].scprod[2] changes. This will show you where the value
is getting messed up.

How you tell the debugger to stop when the value changes depends on
your debugger.

-- Richard
 
M

Mark Bluemel

Matt said:
As requested, here is the section of the code in question. It will
compile, but it is now seg faulting on the first attempt I make to
assign a value to stamps[1].scprod[2]. I'm assuming there is a link
between this and the actual problem.

int main()

{

int i,j;
int im, jm;
int d;

double mean, sigma, sum, *sum_vectors, *check_stack;

stamps = (stamp_struct *)malloc( 196 * sizeof(stamp_struct) );

stamps.scprod = (double *)malloc( 55 * sizeof(double) );


i is uninitialized here. Goodness only knows where you've put the
address of the block of doubles...

(You've also not checked the results of malloc())
 
B

Ben Bacarisse

Matt said:
Thanks for the reply.

As requested, here is the section of the code in question. It will
compile, but it is now seg faulting on the first attempt I make to
assign a value to stamps[1].scprod[2]. I'm assuming there is a link
between this and the actual problem.

/* A programme to test a seg fault error I'm getting */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>

typedef struct

{
int x , y;
double **vectors;
double *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;

stamp_struct *stamps;

int main()

{

int i,j;
int im, jm;
int d;

double mean, sigma, sum, *sum_vectors, *check_stack;

stamps = (stamp_struct *)malloc( 196 * sizeof(stamp_struct) );

stamps.scprod = (double *)malloc( 55 * sizeof(double) );

^
i is indeterminate.
gsl_permutation * indx = gsl_permutation_calloc( 425 );

mean = sigma = 0.0;

printf("Seg_Fault_Test.c: Matrix 'check_mat' declared with size %d
\n" , 425 );
gsl_matrix *check_mat = gsl_matrix_calloc( 425 , 425 );

printf("Seg_Fault_Test.c: Matrix 'check_vec' declared with size %d
\n" , 425 );
gsl_vector *check_vec = gsl_vector_calloc( 425 );

stamps[1].scprod[2] = 10.0;

for( i = 0 ; i < 96 ; i++ )

{

printf("Seg_Fault_Test.c: Begin Pass %d\n",i);

printf("%g\n",stamps[1].scprod[2]); /* SEGMENTATION FAULT HERE ON
2ND PASS FROM i DO LOOP */

printf("Seg_Fault_Test.c: Statement printed successfully\n");

for( im = 1 ; im <= 54 ; im++ )

{

gsl_vector_set( check_vec , im , stamps.scprod[im] );

for( jm = 1 ; jm <= im ; jm++ )

{

gsl_matrix_set( check_mat , im , jm , stamps.mat[im][jm]
);


For this, and the vector set line above, stamps.scprod and .mat
must all have been allocated and set.
}

}

gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , 425 , 425 );
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , 425 );

gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d );

gsl_linalg_LU_svx( &check_mat_view.matrix , indx ,
&check_vec_view.vector );

for( j = 0 , sum = 0.0 ; j < 53 ; j++ )

{

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

}

check_stack = sum;
stamps.norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps.x , stamps.y , sum );

}

return 0;

}


I did in fact correct these errors. The program then reports an error
inside gsl_linalg_LU_decomp. My next action would have been to reduce
the data set size but here I hit a snag. It is not wise to have all
these "magic numbers" peppering your code. There is probably a fixed
and logical relationship between 196, 96, 55, 425, 54 etc. and what I
wanted to find was a:

#define DATA_SIZE_SIZE 55

(or maybe a couple of these) that I could change and have everything
else change in relation to it. When (if?) you post to the gsl help
list, you should have a program that can be altered in this way.

I think you will get better help from the gsl people.
 
M

Matt

Matt said:
As requested, here is the section of the code in question. It will
compile, but it is now seg faulting on the first attempt I make to
assign a value to stamps[1].scprod[2]. I'm assuming there is a link
between this and the actual problem.

int main()

int i,j;
int im, jm;
int d;
double mean, sigma, sum, *sum_vectors, *check_stack;
stamps = (stamp_struct *)malloc( 196 * sizeof(stamp_struct) );
stamps.scprod = (double *)malloc( 55 * sizeof(double) );


i is uninitialized here. Goodness only knows where you've put the
address of the block of doubles...

(You've also not checked the results of malloc())


Bit ashamed I put that out now given the number of mistakes I'm fixing
in it - I'll put up a version closer to what I intended shortly.
 
M

Matt

Matt said:
Thanks for the reply.
As requested, here is the section of the code in question. It will
compile, but it is now seg faulting on the first attempt I make to
assign a value to stamps[1].scprod[2]. I'm assuming there is a link
between this and the actual problem.
/* A programme to test a seg fault error I'm getting */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>
typedef struct
{
int x , y;
double **vectors;
double *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;
stamp_struct *stamps;
int main()

int i,j;
int im, jm;
int d;
double mean, sigma, sum, *sum_vectors, *check_stack;
stamps = (stamp_struct *)malloc( 196 * sizeof(stamp_struct) );
stamps.scprod = (double *)malloc( 55 * sizeof(double) );


^
i is indeterminate.


gsl_permutation * indx = gsl_permutation_calloc( 425 );
mean = sigma = 0.0;
printf("Seg_Fault_Test.c: Matrix 'check_mat' declared with size %d
\n" , 425 );
gsl_matrix *check_mat = gsl_matrix_calloc( 425 , 425 );
printf("Seg_Fault_Test.c: Matrix 'check_vec' declared with size %d
\n" , 425 );
gsl_vector *check_vec = gsl_vector_calloc( 425 );
stamps[1].scprod[2] = 10.0;
for( i = 0 ; i < 96 ; i++ )

printf("Seg_Fault_Test.c: Begin Pass %d\n",i);
printf("%g\n",stamps[1].scprod[2]); /* SEGMENTATION FAULT HERE ON
2ND PASS FROM i DO LOOP */
printf("Seg_Fault_Test.c: Statement printed successfully\n");
for( im = 1 ; im <= 54 ; im++ )

gsl_vector_set( check_vec , im , stamps.scprod[im] );

for( jm = 1 ; jm <= im ; jm++ )

gsl_matrix_set( check_mat , im , jm , stamps.mat[im][jm]
);


For this, and the vector set line above, stamps.scprod and .mat
must all have been allocated and set.


}

gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , 425 , 425 );
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , 425 );
gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d );
gsl_linalg_LU_svx( &check_mat_view.matrix , indx ,
&check_vec_view.vector );
for( j = 0 , sum = 0.0 ; j < 53 ; j++ )

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

check_stack = sum;
stamps.norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps.x , stamps.y , sum );

return 0;


I did in fact correct these errors. The program then reports an error
inside gsl_linalg_LU_decomp. My next action would have been to reduce
the data set size but here I hit a snag. It is not wise to have all
these "magic numbers" peppering your code. There is probably a fixed
and logical relationship between 196, 96, 55, 425, 54 etc. and what I
wanted to find was a:

#define DATA_SIZE_SIZE 55

(or maybe a couple of these) that I could change and have everything
else change in relation to it. When (if?) you post to the gsl help
list, you should have a program that can be altered in this way.

I think you will get better help from the gsl people.


After correcting many silly mistakes, I've got the test program to now
execute without any problems and have included it below in case anyone
is interested. Hopefully by making the same changes to my main program
the seg faults situation will be resolved.

/* A programme to test a seg fault error I'm getting */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>

typedef struct

{
int x , y;
double **vectors;
double *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;

stamp_struct *stamps;

int main()

{

int i , j;
int im;
int d;
int a = 0;
int b = 0;
int matrix_size = 425;
int stamps_size = 196;
int scprod_size = 55;
int sum_num = 53;
int check_vec_size = 54;

double mean, sigma, sum, *sum_vectors, *check_stack;

stamps = (stamp_struct *)malloc( stamps_size *
sizeof(stamp_struct) );

for ( i = 0 ; i < stamps_size ; i++ )

{

stamps.scprod = (double *)malloc( scprod_size *
sizeof(double) );

}

gsl_permutation *indx = gsl_permutation_calloc( matrix_size );

mean = sigma = 0.0;

printf("Seg_Fault_Test.c: Matrix 'check_mat' declared with size %d
\n" , matrix_size );
gsl_matrix *check_mat = gsl_matrix_calloc( matrix_size ,
matrix_size );

printf("Seg_Fault_Test.c: Matrix 'check_vec' declared with size %d
\n" , matrix_size );
gsl_vector *check_vec = gsl_vector_calloc( matrix_size );

/* Give initial values to stamps.scprod[j] */

for( i = 0 ; i < stamps_size ; i++ )

{

for ( j = 0 ; j < scprod_size ; j++ )

{

stamps.scprod[j] = a;
a = ( rand() % 1000 );

}

}

/* Give initial values to check_mat */

for( i = 0 ; i < matrix_size ; i++ )

{

for ( j = 0 ; j < matrix_size ; j++ )

{

b = ( rand() % 100000 );
gsl_matrix_set( check_mat, i , j , b );

}

}

for( i = 0 ; i < stamps_size ; i++ )

{

printf("Seg_Fault_Test.c: Begin Pass %d\n" , i );

printf("stamps[1].scprod[2] = %g\n" , stamps[1].scprod[2] );

printf("Seg_Fault_Test.c: Statement printed successfully\n");

for( im = 1 ; im <= check_vec_size ; im++ )

{

gsl_vector_set( check_vec , im , stamps.scprod[im] );

}

/* gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , matrix_size , matrix_size );
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , matrix_size ); */

printf("Seg_Fault_Test.c: Test 2\n");
printf("check_mat[1][2] = %g\n" , gsl_matrix_get( check_mat , 1 ,
2 ));

/* gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d );
Segmentation fault here */

gsl_linalg_LU_decomp( check_mat , indx , &d ); /* Segmentation
fault here */

printf("Seg_Fault_Test.c: Test 3\n");

gsl_linalg_LU_svx( check_mat , indx , check_vec );

for( j = 0 , sum = 0.0 ; j < sum_num ; j++ )

{

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

}

check_stack = sum;
stamps.norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps.x , stamps.y , sum );

}

return 0;

}



Kind Regards,

Matt
 
B

Ben Bacarisse

Matt said:
After correcting many silly mistakes, I've got the test program to now
execute without any problems and have included it below in case anyone
is interested. Hopefully by making the same changes to my main program
the seg faults situation will be resolved.
double mean, sigma, sum, *sum_vectors, *check_stack;
sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

sum_vectors is not initialised. I suggest you compile and run with
-fmudfalp next time. I suspect that, when the C errors are removed,
you will have a question that does not belong here, but it may take a
while to get there!
 
M

Matt

Matt said:
After correcting many silly mistakes, I've got the test program to now
execute without any problems and have included it below in case anyone
is interested. Hopefully by making the same changes to my main program
the seg faults situation will be resolved.

double mean, sigma, sum, *sum_vectors, *check_stack;
sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

sum_vectors is not initialised. I suggest you compile and run with
-fmudfalp next time. I suspect that, when the C errors are removed,
you will have a question that does not belong here, but it may take a
while to get there!

Thanks for that, though I'm assuming you mean -fmudflap from your
earlier post :)

When I add -fmudflap to the Makefile I get:

cc1: error: mf-runtime.h: No such file or directory

Any idea where this mf-runtime.h should be?

Kind Regards,

Matt
 
B

Ben Bacarisse

Matt said:
Matt said:
After correcting many silly mistakes, I've got the test program to now
execute without any problems and have included it below in case anyone
is interested. Hopefully by making the same changes to my main program
the seg faults situation will be resolved.

double mean, sigma, sum, *sum_vectors, *check_stack;
sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j];

sum_vectors is not initialised. I suggest you compile and run with
-fmudfalp next time. I suspect that, when the C errors are removed,
you will have a question that does not belong here, but it may take a
while to get there!

Thanks for that, though I'm assuming you mean -fmudflap from your
earlier post :)

When I add -fmudflap to the Makefile I get:

cc1: error: mf-runtime.h: No such file or directory

Any idea where this mf-runtime.h should be?

You need to post to a group about your OS. How to drive your tools is
off topic here.
 
J

JimS

stamps = (stamp_struct *)malloc( stamps_size * sizeof(stamp_struct) );

In C, casting the result of malloc is poor style, and in some cases
can mask errors. Also, if the type of 'stamps' changes, then you
would need to modify both the cast and the sizeof. You can avoid both
of those issues by writing

stamps = malloc(stamps_size * sizeof *stamps);

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top