Casting ? Help urgently needed!

Discussion in 'C Programming' started by el prinCipante, Jan 23, 2004.

  1. 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
     
    el prinCipante, Jan 23, 2004
    #1
    1. Advertising

  2. (el prinCipante) wrote in
    news::

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

    --
    - Mark ->
    --
     
    Mark A. Odell, Jan 23, 2004
    #2
    1. Advertising

  3. 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
     
    Thomas Matthews, Jan 23, 2004
    #3
  4. el prinCipante

    gabriel Guest

    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 *
    >
    > 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!

    --
    gabriel
     
    gabriel, Jan 23, 2004
    #4
  5. el prinCipante

    Super Profi Guest

    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 <> wrote in message news:<f3c06$40114ff3$d01d981e$>...
    > 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 *
    > >
    > > 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!
     
    Super Profi, Jan 26, 2004
    #5
  6. 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"?
     
    Peter Shaggy Haywood, Jan 28, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walterd

    Help needed Urgently

    walterd, Jul 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    444
    Lucas Tam
    Jul 26, 2004
  2. Keith
    Replies:
    2
    Views:
    433
    Keith
    Feb 23, 2005
  3. gauravkg via DotNetMonster.com

    XML PROBLEM HELP NEEDED URGENTLY

    gauravkg via DotNetMonster.com, Sep 6, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    318
    Tarren
    Sep 6, 2006
  4. Alfonso Morra
    Replies:
    15
    Views:
    831
    Alfonso Morra
    Aug 12, 2005
  5. Shawn & Jo-an Mehaffie

    Calling Web Services Dynamically - Help Urgently needed

    Shawn & Jo-an Mehaffie, Jul 25, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    149
    Mike Malter
    Jul 26, 2003
Loading...

Share This Page