Like Tree1Likes
  • 1 Post By whiteflags

declaring pointer variable to array of function pointers

This is a discussion on declaring pointer variable to array of function pointers within the C Programming forums, part of the General Programming Boards category; I am having following pointer variable declaration Code: Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos}; Here funcs is an array ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    declaring pointer variable to array of function pointers

    I am having following pointer variable declaration

    Code:
    Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos};
    Here funcs is an array of pointers to functions which take double as input and gives double as output with static as storage type am I right.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,751
    Ask your compiler! And try these steps:

    Write down the function prototype that matches the pointer type you want. Since you are using math functions, that is
    double cos(double);

    Now add parens around the name and an asterisk.
    double (*cos)(double);

    Change the name of the function to an alias and make it a typedef.
    typedef double (*MathFunction)(double);

    Now a declaration of an array of function pointers is:
    Code:
    MathFunction trigfunctions[] = {sin, cos, tan, asin, acos};
    Salem likes this.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,500
    Quote Originally Posted by vlrk View Post
    I am having following pointer variable declaration

    Code:
    Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos};
    Here funcs is an array of pointers to functions which take double as input and gives double as output with static as storage type am I right.
    Looks good to me.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 05-11-2013, 03:43 PM
  2. Replies: 8
    Last Post: 02-04-2012, 03:40 AM
  3. Replies: 11
    Last Post: 12-30-2009, 04:04 PM
  4. Declaring pointer to variable in struct
    By movl0x1 in forum C Programming
    Replies: 5
    Last Post: 07-09-2007, 12:24 PM
  5. declaring function pointer types for callbacks
    By Pea in forum C Programming
    Replies: 6
    Last Post: 01-06-2005, 09:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21