why does not "g++ -Wall" give warning message when compiling the following code?
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 10 楼,当前显示第 3 楼 : 从楼主开始阅读 : 本帖树形列表 : 返回上一页
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2005-10-30 10:20:03  3楼 
using linux/glibc? Segfault because you damaged the link listof freed memory chunks. bype 0-8 of a freed memory chunk contains pointers to the previous/next freed chunks. in for (int i = 0; i < 8; i ++) flag[i] = true; you destroyed the link list. When you try to free the next chunk (darray), free() tries to merge the two adjacent freed chunks. As the link list is corrupted, you see a segfault. There are two ways to avoid segfault with you wrong program: 1. #include using namespace std; int main () { bool * flag = new bool[16]; delete [] flag; double * darray = new double[10]; for (int i = 0; i < 8; i ++) flag[8+i] = true; cout (more...)
but after
but after delete [] flag, when u try to access flag[i], it is wrong, the compiler should be aware of it
This page is intentionally left blank
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表

本帖共有 10 楼,当前显示第 3 楼,本文还有 N-1 层楼,要不你试试看:点击此处阅读更多 >>



请登录后回复:帐号   密码