This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

enum question

These code snippets come from a Dhrystone test we are using to evaluate ARM MDK and some ARM devices. The program works well but I have run across a construct that I do not understand. I hope some of you experts can point out what I'm missing.

In a header file an enum-
typedef enum {Ident_1,Ident_2,Ident_3,Ident_4} Enumeration;

In main() there is a declaration-
Enumeration Func_1();
/* forward declaration since Enumeration may not be int */

I have looked in my 'C' books and googled enum and Enumeration but failed to find any construct examples such as this. Of course I found the normal 'day of the week' and 'color' examples in many locations.

I have no problems with the code. I just don't understand the constructs.

Any guidance would be appreciated.
Bradford

Parents
  • "In a header file an enum-
    typedef enum {Ident_1,Ident_2,Ident_3,Ident_4} Enumeration;

    An easy way to manage typedef syntax is to first define an object of the type (ideally with the object name being what you want to name the type); for example:

    enum {Ident_1,Ident_2,Ident_3,Ident_4} Enumeration;
    

    With that you'd have an int object named "Enumeration" whose values can have those enumerated in the list (in this case 0-3).

    Now simply prefix all that with "typedef". Now "Enumeration" is not a space-allocating object, but rather a type named "Enumeration" with the same type constraints that the former object had.

Reply
  • "In a header file an enum-
    typedef enum {Ident_1,Ident_2,Ident_3,Ident_4} Enumeration;

    An easy way to manage typedef syntax is to first define an object of the type (ideally with the object name being what you want to name the type); for example:

    enum {Ident_1,Ident_2,Ident_3,Ident_4} Enumeration;
    

    With that you'd have an int object named "Enumeration" whose values can have those enumerated in the list (in this case 0-3).

    Now simply prefix all that with "typedef". Now "Enumeration" is not a space-allocating object, but rather a type named "Enumeration" with the same type constraints that the former object had.

Children