Friday, January 15, 2010

NULL, 0x00, '\0'怎么看都是一个东西

void main(int argc, char *argv){
  char a = '\0';
  char b = (char ) 0x00;
  char c = (char )NULL;
  if ( a == b) printf("OK\n");
  if ( a == c) printf("OK\n");
}

输出結果为:
OK
OK

只是NULL对compiler来说, 会测试变量的类型, 如:
char c = NULL;
会报: warning: initialization makes integer from pointer without a cast

如果不信息(char )NULL和 NULL是相同的数值的话, 可以使用:
grep -r "define NULL"
可以看到:
define NULL (0)
define NULL 0
define NULL ((void*)0)


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.