Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
33a7dc93
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
33a7dc93
编写于
1月 05, 2009
作者:
J
Jim Meyering
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HACKING: mention bool and other scalar types, const-correctness
上级
13a22325
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
0 deletion
+57
-0
ChangeLog
ChangeLog
+4
-0
HACKING
HACKING
+53
-0
未找到文件。
ChangeLog
浏览文件 @
33a7dc93
Mon Jan 5 09:11:21 CET 2009 Jim Meyering <meyering@redhat.com>
HACKING: mention bool and other scalar types, const-correctness
Fri Dec 26 14:22:04 CET 2008 Guido Günther <agx@sigxcpu.org>
document vnc's keymap attribute
...
...
HACKING
浏览文件 @
33a7dc93
...
...
@@ -91,6 +91,59 @@ Usually they're in macro definitions or strings, and should be converted
anyhow.
C types
=======
Use the right type.
Scalars
-------
If you're using "int" or "long", odds are good that there's a better type.
If a variable is counting something, be sure to declare it with an
unsigned type.
If it's memory-size-related, use size_t (use ssize_t only if required).
If it's file-size related, use uintmax_t, or maybe off_t.
If it's file-offset related (i.e., signed), use off_t.
If it's just counting small numbers use "unsigned int";
(on all but oddball embedded systems, you can assume that that
type is at least four bytes wide).
If a variable has boolean semantics, give it the "bool" type
and use the corresponding "true" and "false" macros. It's ok
to include <stdbool.h>, since libvirt's use of gnulib ensures
that it exists and is usable.
In the unusual event that you require a specific width, use a
standard type like int32_t, uint32_t, uint64_t, etc.
While using "bool" is good for readability, it comes with minor caveats:
- Don't use "bool" in places where the type size must be constant across
all systems, like public interfaces and on-the-wire protocols.
- Don't compare a bool variable against the literal, "true",
since a value with a logical non-false value need not be "1".
I.e., don't write "if (seen == true) ...". Rather, write "if (seen)...".
Of course, take all of the above with a grain of salt. If you're about
to use some system interface that requires a type like size_t, pid_t or
off_t, use matching types for any corresponding variables.
Also, if you try to use e.g., "unsigned int" as a type, and that
conflicts with the signedness of a related variable, sometimes
it's best just to use the *wrong* type, if "pulling the thread"
and fixing all related variables would be too invasive.
Finally, while using descriptive types is important, be careful not to
go overboard. If whatever you're doing causes warnings, or requires
casts, then reconsider or ask for help.
Pointers
--------
Ensure that all of your pointers are "const-correct".
Unless a pointer is used to modify the pointed-to storage,
give it the "const" attribute. That way, the reader knows
up-front that this is a read-only pointer. Perhaps more
importantly, if we're diligent about this, when you see a non-const
pointer, you're guaranteed that it is used to modify the storage
it points to, or it is aliased to another pointer that is.
Low level memory management
===========================
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录