Thread: array of function pointers ..

  1. #1
    Registered User
    Join Date
    Mar 2008

    array of function pointers ..

    I have program which has an array of function pointers.
    #include <stdio.h>
    int (* arrFunPtr[5])(void);
    void f1(void);
    void f2(void);
    void f3(void);
    void f4(void);
    void f5(void);
    void f1()
            printf("Iam in f1 \n");
    void f2()
            printf("Iam in f2 \n");
    void f3()
            printf("Iam in f3 \n");
    void f4()
            printf("Iam in f4 \n");
    void f5()
            printf("Iam in f5 \n");
    int main()
            int choice=0;
            arrFunPtr[0] = &f1; // line 43
            printf("Please Enter Your Choice  \n");
                    case 1:
                                            printf("zero \n");
                                               printf("Default \n");
            return 0;
    When i compile it , gives me an warning as ..

    ex6.c: In function `main':
    ex6.c:43: warning: assignment from incompatible pointer type

    When i execute it , gives me the desired result.

    Iam concerned about the warming .

    Can any one let me know about this.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Your function pointer array is expecting a return type of int, whilst your f1, f2 ... functions are have a void return type. Fix that and you will not have a warning.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Returning an Array of Pointers to Objects
    By randomalias in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2006, 02:45 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Passing a 2d Array of pointers to a Function
    By miclus in forum C Programming
    Replies: 6
    Last Post: 09-11-2004, 07:34 AM
  5. Array of function pointers?
    By The V. in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2001, 08:37 PM