0
点赞
收藏
分享

微信扫一扫

结构标记的解释(structure tag)

其生 2022-01-23 阅读 47
c语言

在C语言中,标记(tag)是在定义struct, union或enum关键字之后使用的标识符。在下面这个C89标准的例子中:

struct tnode { 
    int count; 
    struct tnode *left, *right; 
}; 

标识符 tnode 是该定义的结构体的标记。
之所以称其为结构体的“tag”而不是“name”,是因为在C语言中,仅使用 tnode 不会指向该结构体(标记为tnode的struct),而需要用 struct tnode。

FILE 在 C 中的定义见下方代码:

struct _iobuf{
    char*   _ptr;
    int     _cnt;
    char*   _base;
    int     _flag;
    int     _file;
    int     _charbuf;
    int     _bufsiz;
    char*    _tmpfname;
};
typedef struct _iobuf FILE;

根据上方的描述,该结构的结构标记是 _iobuf,而非 FILE。

举报

相关推荐

0 条评论