C语言中的声明符说明符是什么?

时间:2016-02-05 07:36:17

标签: c

C语言中的声明符说明符和类型说明符是什么? 用户可以定义或创建声明符说明符或类型说明符吗? 我正在阅读GCC源代码,如果你能给我一些建议,我将非常感谢! 以下是GCC / c-tree.h

/* 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
};

2 个答案:

答案 0 :(得分:3)

C声明

在C语言中,声明的语法格式为:

declaration-specifiers declarator

声明符是变量或函数或指针,基本上对应于声明的对象的名称。

说明符可以是type specifiers,例如int, unsigned, etc.storage class specifier,例如typedef, extern, statictype qualifiers,例如const, volatile, etc.

例如,在以下声明中:

typedef long double DBL;

我们引入了一个新的类型名称 DBL ,它是long double的别名,我们有:

  1. typedef :存储类说明符
  2. long double :类型说明符
  3. DBL :声明者
  4. 当您使用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

答案 1 :(得分:2)

声明符是声明组件,用于指定对象或函数的名称。声明符还指定命名对象是对象,指针,引用还是数组。虽然声明符不指定基类型,但它们会修改基本类型中的类型信息以指定派生类型,如指针,引用和数组。应用于函数时,声明符使用类型说明符来完全指定函数的返回类型作为对象,指针或引用。参考链接Here.这提供了有关声明符的更多信息。

指针声明

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