Page 147 - C-Language
P. 147

Typedef


        Typedefs are declarations which have the keyword typedef in front and before the type. E.g.:


         typedef int (*(*t0)())[5];


        (you can technically put the typedef after the type too - like this int typedef (*(*t0)())[5]; but this
        is discouraged)

        The above declarations declares an identifier for a typedef name. You can use it like this
        afterwards:


         t0 pf;


        Which will have the same effect as writing:


         int (*(*pf)())[5];


        As you can see the typedef name "saves" the declaration as a type to use later for other
        declarations. This way you can save some keystrokes. Also as declaration using typedef is still a
        declaration you are not limited only by the above example:


         t0 (*pf1);


        Is the same as:


         int (*(**pf1)())[5];


        Using the right-left or spiral rule to decipher C declaration


        The "right-left" rule is a completely regular rule for deciphering C declarations. It can also be useful
        in creating them.


        Read the symbols as you encounter them in the declaration...


         *   as "pointer to"          - always on the left side
         []  as "array of"            - always on the right side
         ()  as "function returning"  - always on the right side



        How to apply the rule


        STEP 1

        Find the identifier. This is your starting point. Then say to yourself, "identifier is." You've started
        your declaration.


        STEP 2



        https://riptutorial.com/                                                                             123
   142   143   144   145   146   147   148   149   150   151   152