'NULL' : undeclared identifier
有一个程序:
int main()
{
char *p = NULL;
return 0;
}
编译时:
'NULL' : undeclared identifier
请问要包含哪个头文件进去?
问题点数:80、回复次数:14Top
1 楼kingofvc(提薪像做贼 )回复于 2002-04-17 12:37:07 得分 10
自己define一个 要么包含一些stdio.h之类的很多文件都有的Top
2 楼my12(兔子的萝卜)回复于 2002-04-17 12:39:03 得分 10
VC编译器要加
#include <iostream>
using namespace std;Top
3 楼mathe()回复于 2002-04-17 12:56:50 得分 0
#include <stdio.h>Top
4 楼neptunez()回复于 2002-04-17 13:19:09 得分 10
直接 char *p = 0;就可以了Top
5 楼prototype(原型)回复于 2002-04-17 13:19:09 得分 0
you'd better not use 'NULL' in c++. use '0'.Top
6 楼rapas()回复于 2002-04-17 13:20:57 得分 0
msdn里面怎么不说啊?
还有
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
表示什么意思啊?
我另外加30分Top
7 楼rapas()回复于 2002-04-17 13:26:10 得分 0
prototype(原型):
我看林锐博士写的《高质量c++编程指南》 ,他说:
请写出 char *p 与“零值”比较的 if 语句。(3分)
标准答案:
if (p == NULL)
if (p != NULL)
如下写法均属不良风格,不得分。
if (p == 0)
if (p != 0)
if (p)
if (!)
Top
8 楼poly30(POLY)回复于 2002-04-17 13:32:55 得分 25
1.#include <stdio.h> (TC)
2.#ifdef __cplusplus //如果没有定义__cplusplus
#define NULL 0 //则定义NULL 为 0
#else //否则定义NULL为((void *)0)
#define NULL ((void *)0)
#endif
/*整段意思是什么时候NULL 是数值0还是一个空指针,是编译环境而定(即有没 有 定义__cplusplus */
Top
9 楼rapas()回复于 2002-04-17 13:37:36 得分 0
poly30(POLY):
是编译环境而定(即有没 有 定义__cplusplus ---->>>
我不知道我的编译环境有没有定义__cplusplus,怎么看?
什么时候需要定义?
今天我没有分加了,过几天我再加Top
10 楼poly30(POLY)回复于 2002-04-17 13:46:07 得分 5
自己在程序的开始加上就ok 了。Top
11 楼poly30(POLY)回复于 2002-04-17 13:47:34 得分 0
但是一般此类问题编译器会自动解决,只要把相应的头文件include 就行了。Top
12 楼prototype(原型)回复于 2002-04-17 14:02:07 得分 20
to rapas() :
i don't agree with 林锐博士 on many points in that article ( including this one).
now you do have met trouble with 'NULL', don't you? :p
'NULL' is ok in c, but troublesome in c++ -- a strong typing language.Top
相关问题
- Help!我在VC++中使用函数CreateWaitableTimer(NULL, FALSE, NULL)在build时出现“undeclared identifier”错误
- Help!我在VC++中使用函数CreateWaitableTimer(NULL, FALSE, NULL)在build时出现“undeclared identifier”错误
- 要用NULL的话得包含什么文件?编译告诉我说NULL是undeclared identifier
- 'DDX_FieldDateTimeCtrl' : undeclared identifier?
- Undeclared identifier: 'IWForm2'?
- error 'string' : undeclared identifier
- undeclared identifier错误,help!!!
- error C2065: 'end1' : undeclared identifier
- 'GetProAddress' : undeclared identifier急救!
- error C2065: '_lpw' : undeclared identifier




