尝试用%s输出空指针

来源:互联网 发布:淘宝付款人数多久更新 编辑:程序博客网 时间:2024/05/17 07:17

尝试用%s输出空指针:

#include <stdio.h>int main (void){    printf("%s\n", NULL);    return 0;}

clang:

cuihao@cuihao-arch /tmp $ clang test.ccuihao@cuihao-arch /tmp $ ./a.out(null)

pathcc:

cuihao@cuihao-arch /tmp $ pathcc test.c cuihao@cuihao-arch /tmp $ ./a.out(null)

gcc:

cuihao@cuihao-arch /tmp $ gcc test.c test.c: 在函数‘main’中:test.c:5:5: 警告:对空指针指向内容的读操作(实参 2) [-Wformat]test.c:5:5: 警告:格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘void *’ [-Wformat]cuihao@cuihao-arch /tmp $ ./a.out[1]    5428 segmentation fault  ./a.out

g++:

cuihao@cuihao-arch /tmp $ g++ test.c test.c: 在函数‘int main()’中:test.c:5:24: 警告:格式 ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘long int’ [-Wformat]cuihao@cuihao-arch /tmp $ ./a.out(null)
原创粉丝点击