Thread: To store a function's address as an integer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    68

    To store a function's address as an integer

    I have a struct
    Code:
    typedef struct
    {
        uint8_t type;
        uint8_t num;
        uint8_t id;
    
        int value;
    }EXPR;
    the value field is a quite multipurpose one (depending on type). one of the purposes I want to use is to store a function's address.

    The only way I found to do it
    Code:
    EXPR expr;
    
    int(*fp)(void);
    fp = Foo;
    expr.value = (int)fp;
    But how can I invoke the function?
    With the "proper" pointer I could do
    Code:
    result = fp();
    the question - can I inform a compiler that value is a function's address?
    Last edited by john7; 01-16-2022 at 09:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create vector of objects: store address or copy?
    By deathmetal in forum C++ Programming
    Replies: 22
    Last Post: 08-20-2015, 12:20 PM
  2. how i can store 2^99999 in integer variable
    By 62049913377 in forum C Programming
    Replies: 7
    Last Post: 08-07-2010, 01:09 AM
  3. using char to store an integer in the range [128,127]
    By nikhil22 in forum C Programming
    Replies: 5
    Last Post: 07-26-2008, 09:44 AM
  4. Replies: 2
    Last Post: 12-07-2004, 02:31 AM
  5. Store Bluetooth remote address to a text file
    By labamba in forum C++ Programming
    Replies: 6
    Last Post: 07-09-2004, 06:51 AM

Tags for this Thread