bug-gsl
[Top][All Lists]
Advanced

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

[Bug-gsl] Question concerning code sequences in GSL


From: David Faustner
Subject: [Bug-gsl] Question concerning code sequences in GSL
Date: Tue, 30 Apr 2013 14:03:20 +0200

Dear GNU Scientific Library Team,

 

I've been studying section 35.3: "Providing the function to solve"  in the
GNU Scientific Library Reference Manual and I deal with a command sequence,
where I'm not sure if it is stated correctly.  My question relates to the
powell function according to 

 

     struct powell_params { double A; };

     

     int

     powell (gsl_vector * x, void * p, gsl_vector * f) {

        struct powell_params * params

          = *(struct powell_params *)p;

        const double A = (params->A);

        const double x0 = gsl_vector_get(x,0);

        const double x1 = gsl_vector_get(x,1);

     

        gsl_vector_set (f, 0, A * x0 * x1 - 1);

        gsl_vector_set (f, 1, (exp(-x0) + exp(-x1)

                               - (1.0 + 1.0/A)));

        return GSL_SUCCESS

     }

 

The powell function gets a pointer p to a structure of unknown type (void) as
an argument. So, the content of p is an address of a structure. With the
command (struct powell_params *)p the pointer p gets an explicit
type-assignment (cast) to the structure type powell_params. Nevertheless, the
pointer p still contains an address of a structure. Furthermore, with the
command *(struct powell_params *) one gets access to those structure, whose
address is stored in the pointer p. So, when we read the whole command
sequence struct powell_params * params = *(struct powell_params *)p, a
structure (right-hand side of the command) will be assigned to the pointer
params of type struct powell_params. So far, params doesn't contain the
address of a structure, but the structure itself. But with the command
params->A in the following line of the above mentioned code sequence, which
is equivalent to (*params).A, it's not possible to access the attribute A
because params doesn't contain the address of the structure.

 

If I'm wrong with my argumentation mentioned above, I am grateful for a few
hints for the correct interpretation. Otherwise, it was a great pleasure for
me to support the improvement of the reference manual. Thus, I thank you for
your time and I will remain until further notice.

 

Best regards from Vienna

 

David Faustner

 

--

Dipl.-Ing. David FAUSTNER

Universitätsassistent

 

ACIN | AUTOMATION & CONTROL INSTITUTE

GRUPPE FÜR KOMPLEXE DYNAMISCHE SYSTEME

TECHNISCHE UNIVERSITÄT WIEN | E376

Gußhausstraße 27-29 | A-1040 Wien

 

Tel. +43 (0)1 58801 - 376294

Fax. +43 (0)1 58801 - 37699

address@hidden | www.acin.tuwien.ac.at
<http://www.acin.tuwien.ac.at/> 

 

DVR-Nummer 0005886

 



reply via email to

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