0

初心者の質問があり、インターネットをサーフィンしたところ、次のような定義しか見つかりませんでした

typedef enum
{
    A,B,C,D
}CAP;
CAP a=A; // printf("%d",a); => 1

しかし、私の質問は (スタンフォード CS107 セクション配布資料から) です:

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
} 

nodeType は数値 (1 , 2, 3) であるため、どうして型宣言として使用できるのでしょうか。

nodeType *list;

そしてこれも?

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

それとも、私が見つけることができるようにマニュアルがありますか?アドバイスありがとうございます!

4

1 に答える 1

1

When you define a type with typedef, you can use it wherever a type can be used. It's treated as if you'd used the type that was defined. So:

nodeType *list;

is equivalent to:

enum {Integer, String, List, Nil} *list;
于 2013-07-18T06:47:11.340 に答える