Thread: enum - incomplete type is not allowed

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    42

    Question enum - incomplete type is not allowed

    Hi,

    I have an enum like:
    Code:
    typedef enum mac_type_e	{	
    	STATIC_MAC, 
    	BLACKLIST_MAC	
    } mac_type_t;
    and I want to use this type in a structure that's declared like:

    Code:
    typedef struct lan_mac_s {
    	UINT16 lanmacid;
    	enum mac_type_t lan_mac_type_pp;		// user mac type per port, 20 mac_type_t array, 0 = static, 1 = blacklisted
    now, the compiler tells me:
    Code:
    incomplete type is not allowed
      	enum mac_type_t lan_mac_type_pp;		// user mac type per port, 20 mac_type_t array, 0 = static, 1 = blacklisted 	
      	                ^
    but funny enough, if I remove the preceeding "enum" keyword, it compiles fine. But since I'm wrioting C and not C++, I really should put it there, I'm surprised why it wouldn't let me, aany ideas?

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    Code:
    enum mac_type_e
    This is one type.

    Code:
    mac_type_t;
    This is another name for the same type.

    You don't need to declare "mac_type_t" as an "enum" since that information is already included by virtue of the typedef.

    After all, the main reason someone might typedef an enum (or a struct) is so they don't need to precede their declarations with "enum" (or "struct").

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    42
    yep, got it, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error: Incomplete type is not allowed?
    By Swadesh in forum C++ Programming
    Replies: 4
    Last Post: 10-27-2012, 03:28 PM
  2. Replies: 2
    Last Post: 05-23-2011, 02:04 PM
  3. array type has incomplete element type
    By philgrek in forum C Programming
    Replies: 29
    Last Post: 05-06-2011, 02:42 PM
  4. error: array type has incomplete element type
    By gerger in forum C Programming
    Replies: 8
    Last Post: 10-05-2010, 07:40 AM
  5. "error: incomplete type is not allowed"
    By Fahrenheit in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2005, 09:52 PM

Tags for this Thread