Thread: int pointer to a long int???

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    17

    int pointer to a long int???

    In order to make my code faster, I'm utilizing an option of a DLL
    function to save a state internally.

    I'm using a DLL function w/ following prototype:
    Code:
    int SOMEFUNCTION(double this, void that, . . . , int *phandle)
    The handle allows for internal state to be saved but I am really
    having trouble with syntax and a concept. In the description of
    the parameters phandle it says:
    . . . it is necessary to pass a pointer to a long integer for
    phandle. phandle will store a handle that is used for each
    following call to SOMEFUNCTION. Call SOMEFUNCTIONCLOSE
    when done.
    I've tried various approaches, but none have worked. I did get it
    to compile once with the following:
    Code:
    int *phandle;
    
    for (blah blah blah){
    . . . iReturn SOMEFUNCTION(stuff, . . . , phandle); . . .
    }//end for
    SOMEFUNCTIONCLOSE(phandle);
    Once I ran the code above I got a runtime error that phandle was
    not initialized. What value should I put in phandle? I think that
    my problem is that I am not understanding how to set ". . . a
    pointer to a long integer. . . "
    Could someone please help me understand what they mean?

    Also one more question, this for loop is executed many times. Is
    it necessary to declare this pointer outside of the scope of the for
    loop in order for the state to be "saved?"

    Thanks for your time.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    All it's saying is that it wants a pointer to an integer. In your example, phandle pointers to nothingness.
    Code:
    void foo(int *phandle)
    {
        //...
    }//foo
    
    int main()
    {
        int handle;
    
        foo(&handle);
    
        return 0;
    }//main
    gg

  3. #3
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    Since it specifically says that phanlde must be a pointer to a long int shouldn't it be like this?

    Code:
    int main()
    {
        long handle; // or long int handle;
    
        foo(&handle);
    
        return 0;
    }//main

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> int SOMEFUNCTION(double this, void that, . . . , int *phandle)
    Use the same type that the prototype uses.

    gg

  5. #5
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    Quote Originally Posted by Codeplug
    >> int SOMEFUNCTION(double this, void that, . . . , int *phandle)
    Use the same type that the prototype uses.

    gg
    sorry

    didn't look at it too closely just noticed this
    . . . it is necessary to pass a pointer to a long integer for
    phandle. phandle will store a handle that is used for each
    following call to SOMEFUNCTION. Call SOMEFUNCTIONCLOSE
    when done.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If the description and the code differ, then the code is "right", but most likely buggy (in that it doesn't conform to the description, or is not portable, or whatever). Or the description is just plain wrong.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    int SOMEFUNCTION(double this, void that, . . . , int *phandle)
    In this case, I think there is a fair chance that the code is not right.

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    17
    by using this and that. . .
    I simply did not want to confuse the pointer at hand

    The code and function prototype are correct, but I think that
    there is an error in the descriptions. I did not consider this as
    a possibility when trying to implement it. I'm just not well-
    equipped or confident enough to go pointing fingers (yet).

    Thanks, I'll try these changes suggested by Codeplug

    What about the last part of my post??? Anyone have an answer
    to my scope question?
    Last edited by just2peachy; 12-15-2004 at 08:56 AM.

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    If the variables is declared inside the for block, then its value will be 'lost' for each repetition of the loop. So yes, it needs to be declared before the for loop.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  4. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM