如果我用C或C ++中的`typedef`,当我应该在Typedef的类型的末尾添加`_t`? [英] If I do a `typedef` in C or C++, when should I add `_t` at the end of typedef'ed type?

查看:118
本文介绍了如果我用C或C ++中的`typedef`,当我应该在Typedef的类型的末尾添加`_t`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,当我应该在结尾 _t 添加到的typedef ED类型?

I am confused when should I add the trailing _t to typedef'ed types?

例如,我应该这样做:

typedef struct image image_t;

或本

typedef struct image image;

什么是一般规则?

What are the general rules?

另外一个例子,我应该这样做:

Another example, should I do this:

typdef enum { ARRAY_CLOSED, ARRAY_OPEN, ARRAY_HALFOPEN } array_type_t;

或本

typdef enum { ARRAY_CLOSED, ARRAY_OPEN, ARRAY_HALFOPEN } array_type;

请赐教。

谢谢,博大Cydo。

推荐答案

在POSIX,用 _t 结尾的名称被保留,因此,如果你的目标POSIX的系统(如:和Linux),你不应该 _t 结束你的类型。

In POSIX, names ending with _t are reserved, so if you are targeting a POSIX system (e.g., Linux), you should not end your types with _t.

这篇关于如果我用C或C ++中的`typedef`,当我应该在Typedef的类型的末尾添加`_t`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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