永发信息网

在dev c++上不行但是在CodeBlocks上行

答案:2  悬赏:40  手机版
解决时间 2021-01-13 22:04
  • 提问者网友:寂寞撕碎了回忆
  • 2021-01-13 19:07
在dev c++上不行但是在CodeBlocks上行
最佳答案
  • 五星知识达人网友:十年萤火照君眠
  • 2021-01-13 19:25
主要是 这句代码 p=malloc(sizeof(struct list)); 引起出错! C支持这种void* 转换到其它类型的比如 struct list *,但C++不支持了.所以,如果在C++中,得自己进行强制转换.
由于不同版本C标准支持不同导致.用回支持C99编译器没问题.比如BCC55可以直接编译并成功运行.用Gcc 编译时选择参数 gcc -Wall  -std=c99 main.c -o main 能编译通过.如果用了 g++ -Wall -std=c++11  main.cpp -o main 编译肯定出错.
from 网页链接
In C, a void* is implicity convertible to a T* where T is any type. From section 6.3.2.3 Pointersof the C99 standard:
A pointer to void may be converted to or from a pointer to any incomplete or object type. A pointer to any incomplete or object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
malloc() returns a void* and is assignable without casting to head, a struct node*. This is not true in C++, so I suspect a C++ compiler is being used to compile this C code.
洋文的大意是说,C99标准支持,而你可能是用了C++编译器来编译了. 建议用回标准C编译器.
追问大佬
全部回答
  • 1楼网友:爱难随人意
  • 2021-01-13 20:18
会不会dev c++上默认c追答说错了,默认c++?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯