Using typedef enum as a new type -


i got beginner question , i've surfed through internet , find definition like

typedef enum {     a,b,c,d }cap; cap a=a; // printf("%d",a); => 1 

but question (from stanford cs107 section handout ) :

typedef enum {   integer, string, list, nil  } nodetype;  // skip char *concatall(nodetype *list)  {   switch (*list) {   case integer:   case nil: return strdup("");   case string: return strdup((char *)(list + 1));   }   nodetype **lists = (nodetype **)(list + 1);   // skip after }  

since nodetype numeric (1 , 2, 3), how come used type declaration

nodetype *list; 

and this?

nodetype **lists = (nodetype **)(list + 1);  

or maybe there's manual can find? thank kind advice!

when define type typedef, can use wherever type can used. it's treated if you'd used type defined. so:

nodetype *list; 

is equivalent to:

enum {integer, string, list, nil} *list; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -