指向结构的指针的 C typedef [英] C typedef of pointer to structure

查看:29
本文介绍了指向结构的指针的 C typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下代码:

typedef struct {
        double x;
        double y;
        double z;
} *vector;

这是一个有效的类型定义吗?代码编译并运行良好.我只是好奇这是否是常见做法.

Is this a valid type definition? The code compiles and runs fine. I was just curious if this is common practice.

推荐答案

绝对有效.通常,您可以通过将两种类型一起定义来充分利用这种方式:

Absolutely valid. Usually, you can take full advantage of this way by defining two types together:

typedef struct
{
 int a;
 int b;
} S1, *S1PTR;

其中 S1 是一个结构体,S1PTR 是指向该结构体的指针.

Where S1 is a struct and S1PTR is the pointer to this struct.

这篇关于指向结构的指针的 C typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆