el prinCipante wrote:
I'm getting tired of the following error message.
Compiler Error message : Error: Need explicit cast to convert
from: float
to: float *
I am trying to use a routine from the Numerical Recipes library called
amebsa.c. The routine requires several parameters of the following
form. *iter, **p, *yb.... . How does one initialize these variables?
If I declare them as pointer (in this case, *yb and *iter) the
compiler still tells me that it needs an explicit cast to covert the
variables from: float to: float *.
Surprisingly the compiler seems to accept the variable defined as **p,
which I initialized that way (float **P;)
additionally I don't know how to use void functions!! Where is the
result of the routine being stored?
Since this the basis of my thesis, I would really be grateful for any
ideas or suggestions!!!
Thanks folks
I believe you need to review the pointers topic in your
favorite C language reference.
The term "float *" refers to a pointer to a variable of type
float, such as:
float my_float_variable;
float * pointer_to_float;
/* ... */
pointer_to_float = &my_float_variable;
The line above makes the pointer point to "my_float_variable".
The term "float * *" refers to a pointer that points to
a pointer to float, also known as double indirection. This
type is commonly used when a function wants to change the
contents of a pointer (i.e. make the pointer point to
another variable).
void initialize_a_pointer(float * * ptr_ptr_float)
{
*ptr_ptr_float /* reference the pointer */
= malloc(sizeof float); // get a pointer from
// dynamic memory
return;
}
int main(void)
{
float * ptr_to_float; /* Declare a pointer. */
/* The content is not set. */
initialize_a_pointer(&ptr_to_float);
/* The above call will allocate a float variable
* from dynamic memory and set "ptr_to_float" to
* point to it.
*/
*ptr_to_float = 3.14159264;
printf("float value is %f\n", *ptr_to_float);
return;
}
Notes:
1. The result from malloc() should be checked for NULL,
which indicates that the allocation failed.
2. If the pointer is null, then the assignment of
3.14159264 will fail (or cause undefined behavior).
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book