莫名其妙的编译异常
莫名其妙的编译错误看下这这小段代码C/C++ code#include stdlib.h#include stdio.h#include string.h
莫名其妙的编译错误
看下这这小段代码
C/C++ code#include <stdlib.h>#include <stdio.h>#include <string.h>int main(){ char buf[6]; //单独注释掉这段没有错误 while (1) { fgets(buf, 6, stdin); printf("%s", buf); } ////////////////////////////////////////////////////////////////////////// //单独注释掉这段也没有错误 int *p1 = malloc(10 * sizeof(int)); int *p2 = calloc(10, sizeof(int)); free(p1); free(p2); ////////////////////////////////////////////////////////////////////////// return 0;}
里面有两小段不相关的代友,这是我测试时写的,但是两段代码注释掉其中任意一段,都没有编译错误,但两段代码同时编译的话,就报错,下面是错误:
代码本身应该没有问题,不清楚为什么?以前也经常遇到。编译器是vs2008
[解决办法]