mpq_t array in sub-functions

delta trinity
Tue, 11 Mar 2003 12:44:24 -0500

Simple programing mistake, not GMP related really... ;-)

What happen is that in the function:
void assignValue(mpq_t x[], int size){
   mpq_t *R;



You initialize R as an array of 15 mpq_t (hardcoded value).
Then, in the main, when you come to call


this create a bug, in the assignValue function, when comming to

which assign values to R as an array of 'size' (20 in this case) when R is 
allocated only 15 mpq_t


>From: "E Lau" <>
>Subject: mpq_t array in sub-functions
>Date: Tue, 11 Mar 2003 00:25:22 -0500
>Hi all:
>I am new to GMP, so I was wondering if someone can give me a hint here.  I 
>was trying to define an array in mpq_t.  It works fine when I define this 
>array in the main function.  However, when I define this array in a sub 
>function, the program generate seg fault.  I attached the sample C file 
>here.  The function "void assignValue(mpq_t x[], int size)" contains 4 
>commented-out lines of code which are causing seg faults in the simple test 
>I'm open to comments and suggestions.  Thanks.
>Edmond Lau

STOP MORE SPAM with the new MSN 8 and get 2 months FREE*