Casting ? Help urgently needed!

E

el prinCipante

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
 
M

Mark A. Odell

(e-mail address removed) (el prinCipante) wrote in

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;)

If you have a pointer to float:

float *pFloatVar;

Then you can call a function that expects a pointer to a pointer to
float:

someFunction(&pFloatVar);
additionally I don't know how to use void functions!! Where is the
result of the routine being stored?

Void functions return nothing. The function will point your pointer to the
answer (the return value if you will).
 
T

Thomas Matthews

el said:
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
 
G

gabriel

el said:
I'm getting tired of the following error message.
Compiler Error message : Error: Need explicit cast to convert
from: float
to: float *

Since this the basis of my thesis[...]

If you do not understand pointers at this stage, you are better off
buying a C/C++ book. Your questions just show a deep lack of
understanding of poitners, so you need to fully understand the difference
between "float" and "float *", and you need to know why void functions
can still return results through pointers.

If you are pressed for time, then I would run out and get a mathematical
program (spending $1000 for Methematica is much cheaper than the time you
will spend mastering C in order to run some routines).

Or you could hire a computer science student to do it right. You do not
want to get a result, and then realize (or not realize) that the result
you gave was actually a memory address and not the actual result!
 
S

Super Profi

Hello Gabriel,

Contact me off list from my web site
http://www.megaone.com/expert2003/consultant.htm
I shall work your assignment out instead of you for a fee.

Mr. Fairman


gabriel said:
el said:
I'm getting tired of the following error message.
Compiler Error message : Error: Need explicit cast to convert
from: float
to: float *

Since this the basis of my thesis[...]

If you do not understand pointers at this stage, you are better off
buying a C/C++ book. Your questions just show a deep lack of
understanding of poitners, so you need to fully understand the difference
between "float" and "float *", and you need to know why void functions
can still return results through pointers.

If you are pressed for time, then I would run out and get a mathematical
program (spending $1000 for Methematica is much cheaper than the time you
will spend mastering C in order to run some routines).

Or you could hire a computer science student to do it right. You do not
want to get a result, and then realize (or not realize) that the result
you gave was actually a memory address and not the actual result!
 
P

Peter Shaggy Haywood

Groovy hepcat el prinCipante was jivin' on 23 Jan 2004 08:08:04 -0800
in comp.lang.c.
Casting ? Help urgently needed!'s a cool scene! Dig it!
I'm getting tired of the following error message.
Compiler Error message : Error: Need explicit cast to convert
from: float
to: float *

Then stop trying to convert a float to a pointer. What on Earth are
you doing that for? It's a rather silly thing to do, not to mention
illegal.
I am trying to use a routine from the Numerical Recipes library called
amebsa.c. The routine requires several parameters of the following

For those of us who haven't read that book and consequently don't
know the file or function, please state its purpose, prototype and
definition (code).
form. *iter, **p, *yb.... . How does one initialize these variables?

Mu. Without knowing the slightest thing about the function, how can
we say what to pass to it?
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;)

And, to what does this pointer point?
additionally I don't know how to use void functions!! Where is the

What do you mean? void functions are functions that simply return
void (ie., no value). You simply call such a function, and don't use
the (non-existant) return value in an expression. What's the problem?
What don't you understand?
result of the routine being stored?

What result? A void function doesn't have a result (return value).
Since this the basis of my thesis, I would really be grateful for any
ideas or suggestions!!!

You're writing a thesis without knowing the first thing about the
subject thereof? Good luck! You'll need it.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top