Thread: What is this mean!

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    Question What is this mean!

    I saw following statement in a C program. But I do not understand what exactly it means.

    Code:
    void (* const text[]) (void) = { &_one,two,three};
    It looks like a function but i see '=' and the pointer notation '*'; bit confused. Could anyone explain me what is that?
    This program is for an microcontroller (Anyway it does not matter I guess)

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It defines text as a array of const pointers to functions that accept no arguments and return void.

    The stuff after the equals sign initialises the array. _one, two, and three are presumably all functions that accept no arguments and return void. So text is an array of three function pointers.

    The const just means that the elements of the array cannot be changed after initialisation.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    Hi Grumpy,

    Thanks for great explanation! I understood alomost everything except the syntax.

    I did little more research. Please look at this

    Code:
    int (*FunA[3])(float, char, char) = {one,two,three,four};
    This is a array for 4 function pointers.
    1. All these 4 function accept 3 values and their types are (float , char , char). Is it true?
    2. All these 4 functins will return int. That means "FunA" can not have pointer of a function that returns float. Is it true?
    3. If above two statements are true, What I understand is "arrary of function pointer is make sense when all functions are return same type and accepts same type". Is my understanding correct?


    One more unrelated question
    Waht is the difference of following two declaration
    int *i;
    int* i;

    Again Thanks for your time!

Popular pages Recent additions subscribe to a feed

Tags for this Thread