这段代码codeblocks能正常运行,vs2012中运行时eval时报出错误,原因在于空指针不能判空。
做个小测试,给p4分配空间,其他什么都不做,按理说p4->l和p4->r都是null,测试显示都不是null。
把代码搬到codeblocks中,能判空,正常运行。
结论:编译器不一样,政策可能就不一样;vs中应该用别的方法来判空。
小测试
int flag=0;
struct ast *p1=(struct ast*)malloc(sizeof(struct ast));
struct ast *p2=(struct ast*)malloc(sizeof(struct ast));
struct ast *p3=(struct ast*)malloc(sizeof(struct ast));
struct ast *p4=(struct ast*)malloc(sizeof(struct ast));
if