C header file/ source file - enum typedef -


if got declaration in header file (.h)

typedef enum {start, end, startemd, comments, directive} baltype; typedef struct bal * bal; 

when come in .c (source file), want create struct bal , include in attribute baltype can tell later type of bal. i've defined struct :

struct bal {     enum baltype type;     char * name;     char * attrone;     char * attrtwo; }; 

but error : error: field type has incomplete type. guess error on typedef enum.

thanks you.

first things first, typedef creates "first-class" type, shouldn't it's enumeration anymore when using it. correct way along lines of:

typedef enum {a, b} c; c c;                    // not enum c c. 

secondly, consider following 2 segments:

typedef enum {a, b} c; enum c d; 

the first creates untagged enumeration , creates type alias c it. second creates separate tagged enumeration (tagged c) , creates no type alias (it declares variable d that's not important our considerations here).

now may wondering has question if take name used when creating type, , place below name used within struct, hope become apparent:

baltype baltype    ^    clue :-) 

so simplification of problem remarkably similar abcd code gave above:

typedef enum {start, end} baltype; enum baltype type; 

it's combination of 2 things giving grief. seem creating complete enumerated type, , are. however, create totally different (and incomplete, since has no body) enumeration. being incomplete, cannot used in manner need.

to solve it, final line above (and first within struct) should replaced with:

baltype type; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -