[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] gsl_vector_alloc question.

From: John Lamb
Subject: Re: [Help-gsl] gsl_vector_alloc question.
Date: Wed, 14 Jul 2004 09:31:27 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040114

Sang Oh wrote:
I'm trying to allocate memory in a function.

void ruler(double xa, double xb, double dx, gsl_vector *vc) {
 vc = gsl_vector_alloc(len);

Looks like a common programming error, nothing to do with gsl. You cannot globally change the _value_ of a parameter. You can only change the value of the struct it points to. The gsl_vector_alloc call just changes a local copy of vc and then throws it away when the function returns, leaving a vector on the heap that you can't point to.

Try rewriting as

gsl_vector *ruler(double xa, double xb, double dx){
  vc = gsl_vector_alloc(len);
  return vc;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]