CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

'NULL' : undeclared identifier

楼主rapas()2002-04-17 12:35:01 在 C/C++ / C语言 提问

有一个程序:  
  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

关键词

  • c++
  • 编译
  • 文件
  • null
  • 定义
  • cplusplus
  • 编译环境
  • define
  • including

得分解答快速导航

  • 帖主:rapas
  • kingofvc
  • my12
  • neptunez
  • poly30
  • poly30
  • prototype

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo