Thread: How to typedef and use it.

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    How to typedef and use it.

    Hello All,

    I have to declare an array of function pointer return char and accepting nothing.

    Code:
    UCHAR(*s[12])(void) = {abc, def, ghi,                                            klm,xyz,
                                        mnp,bcd,stp,
                                        ghk,jwe,
                                        uvw,hik};
    But I want to know, How do I typedef the pointer declaration and use in defining the array.

    Please advise.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Just typedef the function pointer - adding an array to the type is possible, but seldom as useful

    Code:
    typedef UCHAR (*fnptr)(void);
    
    fnptr s[12] = { abc, etc, etc };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    typedef UCHAR (*pfunc)(void);
    pfunc s[12] = { abc, def, ghi, klm, xyz, mnp, bcd, stp, ghk, jwe, uvw, hik };
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Thanks

Popular pages Recent additions subscribe to a feed