Hi all,
I've got a segmentation fault occurring that I don't understand, and I'd appreciate your help. First, the relevant structure
Code:
typedef struct node
{
//sequence for this node
amino_acid_list *sequence;
// not currently used- in case sequence length changes
int sequence_length;
// distance (in amino acid substitutions)
int mutation_distance_from_parent;
int mutation_distance_to_left;
int mutation_distance_to_right;
// distance (absolute? not yet used)
int distance_from_parent;
int distance_to_left;
int distance_to_right;
// depth of this node
int depth;
// debugging
long int data;
// pointers
struct node *parent_ptr;
struct node *left_ptr;
struct node *right_ptr;
} node
Here is the function definition
Code:
node *build_tree_with_constraints(node *n, node* nprev, int depth, int maxdepth, amino_acid_list *parent_sequence, int sequence_length, float ........r, float **tpm, int dist, float random_param_one, float random_param_two, int burnin, incompatability_matrix **icm, int num_amino_acids, int type, int *num_mutations);
And here is the offending piece of code within the function build_tree_with_constraints
Code:
n->left_ptr= build_tree_with_constraints(n->left_ptr, n, n->depth+1, maxdepth, n->sequence, sequence_length, ssr, tpm, dist, random_param_one, random_param_two, burnin, icm, num_amino_acids, type, num_mutations);
// make sure that we get the correct output here
printf("LEFT- number of mutations is %d\n", *num_mutations);
// set the distance to the left offspring node
n->mutation_distance_to_left= *num_mutations;
printf("one\n");
n->left_ptr->mutation_distance_from_parent= *num_mutations;
printf("two\n");
Here is the output
Code:
number of mutations is 48
LEFT- number of mutations is 48
uno
Segmentation fault
I don't understand why
Code:
n->mutation_distance_to_left= *num_mutations;
works, but
Code:
n->left_ptr->mutation_distance_from_parent= *num_mutations;
Doesn't. I've also tried
Code:
(n->left_ptr)->mutation_distance_from_parent= *num_mutations;
But that doesn't help either. So obviously I'm missing something fairly basic, but I don't know what it is.
Thanks a lot,
Brad