C 语言类型命名规则的一点疑惑
这个问题是放在 101 新手上路 的,请各位大大勿喷…
最近在看一些开源的 C 项目,发现大大们在给自定义的类型命名的时候都喜欢以 _t
结尾;然后我去看 stdint.h
里诸如 int32_t
、int64_t
这类也是加 _t
后缀。
- hihocoder#1034 毁灭者问题,提交总是WA
- 现在已经使用CommandArgument取到t_ID的值,现在还想取t_Name的值一起放到cs文件中的sql语句中该怎么做
- PHP源码,C代码
- C#中使用DirectDraw,在退出时需要进行处理吗?
- 控制台程序如何实现tab键自动补全?
在网上搜了一圈没找到有介绍这种命名方式的文章,Google C++ Style Guide 里也没有提到。
很好奇加 _t
后缀是否就是表示这是一个类型(type)
的意思?这是一种命名法?叫什么?
不知道哪位大大有相关的资料?~
【2016.09.14 23:49 补充】
大家不要太过于把注意点集中在 stdint.h
,我只是随便举的一个例子。。另外这里还有一个例子可以参考一下:
https://github.com/luohaha/Do…
- c 用fopen函数以w模式打开,再fputs写了两句话,但多打印出很多“屯”?
- 怎么写服务器端?
- C++学习相关路线
- sizeof("001\001")【写错了】
- 如何将静态库转成动态库(Visual Studio)?
- C#调用CodeSoft打印条码 ,未将对象引用设置到对象的实例怎么解决?
- 实际获得的动态分配内存的大小怎么确定
- 新浪微博联合登录 授权之后 跳转到回调页面 报错:远程服务器返回错误:(401)未经授权
那样一般是typedef搞出来的←_←
这是用了 C99
加入的 <stdint.h>
中的固定字长整数类型。因为不同平台整形的长度可能不一样。可参看 How to C in 2016 中 Types 部分,中文翻译版本。
stdint.h
是C99
加入的。
据我所致_t
后缀表示的结构或类型约定为黑盒类型,也就是说其中的属性对外不可见,需要使用函数来操作。当然,这只是一种说法,并不绝对。参考apr
I will describe the meaning of the code. Here, please take a look at only style. You can see apr_ prefix. The apr_ prefix indicates that the symbol is in libapr naming scope. You can see _t suffix. It indicates that the symbol is a type name.
apr_pool_t is opaque type. It means the type's structure is not public.
By OO(Object Oriented) terminology, all member variables are private. You can’t touch them directly. Furthermore, you can’t see them in public header files. All you can do for the type is to call APIs such as apr_foo_bar() functions. Most importantly, you can’t allocate their instance memories directly. All you can do is to call construct APIs. Only libapr knows how to construct and destruct the objects.
另外,在nginx
中,通常以_s
来定义结构,并用typedef
重新声明成_t
_t表示内部类型,是*nix kernel的命名习惯,不必纠结这些,再就是#include <inttypes.h>
,它#include <stdint.h>
了,而且不仅仅是这样。
Linux style naming