2016-02-05 97 views
1

什麼是C語言中的聲明符說明符和類型說明符? 用戶可以定義或創建聲明符說明符或類型說明符嗎? 我正在閱讀GCC源代碼,如果你能給我一些建議,我會非常感謝! 下面是從GCC/C-tree.h中C語言中的聲明符說明符是什麼?

/* A kind of type specifier. Note that this information is currently 
    only used to distinguish tag definitions, tag references and typeof 
    uses. */ 
enum c_typespec_kind { 
    /* No typespec. This appears only in struct c_declspec. */ 
    ctsk_none, 
    /* A reserved keyword type specifier. */ 
    ctsk_resword, 
    /* A reference to a tag, previously declared, such as "struct foo". 
    This includes where the previous declaration was as a different 
    kind of tag, in which case this is only valid if shadowing that 
    tag in an inner scope. */ 
    ctsk_tagref, 
    /* A reference to a tag, not previously declared in a visible 
    scope. */ 
    ctsk_tagfirstref, 
    /* A definition of a tag such as "struct foo { int a; }". */ 
    ctsk_tagdef, 
    /* A typedef name. */ 
    ctsk_typedef, 
    /* An ObjC-specific kind of type specifier. */ 
    ctsk_objc, 
    /* A typeof specifier, or _Atomic (type-name). */ 
    ctsk_typeof 
}; 
+0

這是一篇關於您的查詢的好文章。 [聲明和C中的聲明](http://stackoverflow.com/questions/13808932/what-are-declarations-and-declarators-and-how-are-their-types-interpreted-by-the) –

回答

2

聲明符是聲明指定的對象或功能的名稱的組件。聲明符還指定指定的對象是否是對象,指針,引用或數組。雖然聲明符不指定基本類型,但它們會修改基本類型中的類型信息以指定派生類型,例如指針,引用和數組。應用於函數,聲明符與類型說明符一起工作,以完全指定函數的返回類型爲對象,指針或引用。參考鏈接Here.其中提供了有關聲明符的更多信息。

說明符爲指針

int *i; // declarator is *i 
int **i; // declarator is **i; 
3

宣言用C


在C爲聲明語法是以下形式:

declaration-specifiers declarator 

聲明者是變量或函數或指針,並且基本上對應於聲明的對象的名稱。

可以type specifiersint, unsigned, etc.storage class specifiertypedef, extern, statictype qualifiersconst, volatile, etc.

例如,在下面的聲明:

typedef long double DBL; 

我們已經推出了一種新型的名字DBL這是long double的別名,我們有:

  1. 的typedef:存儲類說明
  2. 長雙:類型說明符
  3. DBL:聲明符

當您使用的typedef你基本上走樣類型說明符用新名稱。如果您在下面的typedef一個結構類似:

typedef struct { 
    int a; 
    int b; 
} mystruct; 

然後裏,可以指定一個變量的類型是MYSTRUCT,如以下聲明:

mystruct c; 

相關文章: What are declarations and declarators and how are their types interpreted by the standard?How do I use typedef and typedef enum in C?Declaration specifiers and declarators