+ -
当前位置:首页 → 问答吧 → 收集因为 误使用保留名字, 而造成的比较难以察觉调试的bug?

收集因为 误使用保留名字, 而造成的比较难以察觉调试的bug?

时间:2010-06-27

来源:互联网

收集因为 误使用保留名字, 而造成的比较难以察觉调试的bug?

我感觉好像这种情况不会发生,所以问问大家?

作者: peidright   发布时间: 2010-06-27

defau1t

作者: starwing83   发布时间: 2010-06-27

中文分号

作者: 没本   发布时间: 2010-06-27

lz用msvc吗?  试试:
  1. __declspec(dllexport) void f(void) {}
  2. __declspec(dllexport) void _imp__f(void) {}
  3. >>> cl /LD xxx.c
复制代码
不过这个不难调试, 因为立马会导致编译器崩溃。

我不知道许多人是从哪学的坏习惯, 要使用下划线开始的名字, 很酷?

有人用 _Bool,_Complex, _Pragma吗?  恭喜, 别想不改源代码就升级到C99
有人用 _Align, _Thread_local吗? C1x打算也开始使用这些名字了。

作者: OwnWaterloo   发布时间: 2010-06-27

回复 OwnWaterloo


    是的,在看libc文档,上面也提到了,许多保留字,都是以_开头。。所以我决定不用。_*, __*开头的的变量。
但是,我还是非常想用四个,或者5个____*的。。。。个给人感觉,下划线,就是某种特殊的代名词,而基本字符集中,
没有其他特别的字母,能比较好的表达“特殊”这个概念。

作者: peidright   发布时间: 2010-06-27

回复 peidright

libc是语言的组成部分。
保留的名字有一部分就是给libc用的。
另一部分是给编译器扩展用的。

它们使用这些名字是理所当然, 而且是必须的。
为了避免和用户代码的名字冲突。

4-5个也不行, 因为那也算是以下划线开始。

要特殊么。。。  后缀下划线。。。?
和前缀下划线相比, 不太明显……


当年C语言也没多考虑用户感受……
现在什么C#, python 都是把前缀下划线提供给用户使用……

作者: OwnWaterloo   发布时间: 2010-06-27

回复 OwnWaterloo


       In addition, some individual header files reserve names beyond those that they actually
define. You only need to worry about these restrictions if your program includes that
particular header file.
  • The header file ‘dirent.h’ reserves names prefixed with ‘d_’.
  • The header file ‘fcntl.h’ reserves names prefixed with ‘l_’, ‘F_’, ‘O_’, and ‘S_’.
  • The header file ‘grp.h’ reserves names prefixed with ‘gr_’.
  • The header file ‘limits.h’ reserves names suffixed with ‘_MAX’.
Chapter 1: Introduction                                                                 7
• The header file ‘pwd.h’ reserves names prefixed with ‘pw_’.
• The header file ‘signal.h’ reserves names prefixed with ‘sa_’ and ‘SA_’.
• The header file ‘sys/stat.h’ reserves names prefixed with ‘st_’ and ‘S_’.
• The header file ‘sys/times.h’ reserves names prefixed with ‘tms_’.
• The header file ‘termios.h’ reserves names prefixed with ‘c_’, ‘V’, ‘I’, ‘O’, and ‘TC’;
   and names prefixed with ‘B’ followed by a digit.

gnu libc 里面,还有这些。。。,以字母开头的,真是混

作者: peidright   发布时间: 2010-06-27

回复 peidright

嗯, 除了下划线, 还保留了其他很多。
这是posix保留的吧?

C语言还保留了 str*, mem* 其他还有一些。
vim的文档里也有写……

作者: OwnWaterloo   发布时间: 2010-06-27

有一次,定义了一周七天的枚举类型,
从mon,tue,到sun。
结果在sun的机器上编译就悲剧了。

作者: lenovo   发布时间: 2010-06-27



QUOTE:
有一次,定义了一周七天的枚举类型,
从mon,tue,到sun。
结果在sun的机器上编译就悲剧了。
lenovo 发表于 2010-06-27 21:49




    囧

作者: zhaohongjian000   发布时间: 2010-06-27