Thread: Help with function Pointer

  1. #1
    Registered User
    Join Date
    Oct 2010

    Help with function Pointer

    Hi, i have a question about function pointer. I am implementing a structure inside a microcontroller's program, to deal with some programed events. On my function pointer definition i am using as an argument a void pointer that receives many different structures as argument according to the function called. But some specific functions have no need arguments, and my problem is that i cant pass a void argument to a void pointer... well i dont know how... any idea on how to do that? For now i have to deal with both on different places.

    FOr now i am using something like

    typedef void (*arg_service_t)(void* service_param); //Service with argument
    typedef void (*service_t)(void); //Service with no argument

    Thank you!

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    Why don't you just pass NULL and test for that in your function.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Maybe this will help: If a function signature is (void), the compiler will throw an error if you call the function with a parameter. However, if a function signature is (), the compiler doesn't care what you pass -- it just ignores the parameters.

    void somefunc(void);    // cannot be called with any parameters
    void somefunc();     // parameters are ignored
    Also, you can always include a void* in the signature but ignore it in the function:
    void somefunc(void *ignored);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing method pointer as a function pointer
    By sevcsik in forum C++ Programming
    Replies: 5
    Last Post: 12-30-2007, 06:19 AM
  2. Replies: 7
    Last Post: 07-04-2007, 12:46 PM
  3. Replies: 9
    Last Post: 01-02-2007, 04:22 PM
  4. Replies: 4
    Last Post: 11-05-2006, 02:57 PM
  5. Replies: 6
    Last Post: 11-29-2004, 08:50 AM