2016-02-05 368 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