你如何处理NUL? [英] How do you deal with NUL?

查看:187
本文介绍了你如何处理NUL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,当我们谈论NULL时,我遇到了与其他程序员的通信问题。现在NULL可以是



一个NULL指针

NUL字符

某种数据库中的空数据元素。 p>


NUL似乎是最让人困惑的。它是ASCII字符0x00。

我倾向于在代码中使用'\0'来表示它。我的组

中的一些开发人员倾向于只使用0,并让编译器隐式地将其转换为char。




你喜欢使用NUL吗?为什么?

解决方案

我使用'\0' nul字符和 NULL 用于指针,因为它在两种情况下都是最清晰的。



BTW, 0 '\0'中的 int ,当存储在中时,任一个将转换为 char char 变量。


From time to time, I run into communications issue with other programmers, when we talk about NULL. Now NULL could be

a NULL pointer
the NUL character
an empty data element in some sort of database.


NUL seems to be the most confusing. It is the ASCII character 0x00.
I tend to use '\0' in my code to represent it. Some developers in my group
tend to prefer to simply use 0, and let the compiler implicitly cast it to a char.


What do you prefer to use for NUL? and why?

解决方案

I use '\0' for the nul-character and NULL for pointers because it is clearest in both cases.

BTW, both 0 and '\0' are ints in C and either one will be converted to char when stored in a char variable.

这篇关于你如何处理NUL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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