Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在aix中使用free()函数时(static area free())_C_Aix - Fatal编程技术网

在aix中使用free()函数时(static area free())

在aix中使用free()函数时(static area free()),c,aix,C,Aix,我不擅长英语,所以请理解我 如果您查看下面的代码,您可以释放()静态区域,但它没有消失。当然,在Linux上,它们会消亡,但在AIX(测试机7.1)上不会 我想知道为什么。 那么空闲的()是什么类型的内存呢 #包括 char-testbuf[512]; void main() { char*p=NULL; p=testbuf; printf(“在本地:%llx静态:%llx\n”,p,testbuf之前); 自由基(p); printf(“在空闲本地:%llx静态:%llx\n”,p,testb

我不擅长英语,所以请理解我

如果您查看下面的代码,您可以释放()静态区域,但它没有消失。当然,在Linux上,它们会消亡,但在AIX(测试机7.1)上不会

我想知道为什么。 那么空闲的()是什么类型的内存呢

#包括
char-testbuf[512];
void main()
{
char*p=NULL;
p=testbuf;
printf(“在本地:%llx静态:%llx\n”,p,testbuf之前);
自由基(p);
printf(“在空闲本地:%llx静态:%llx\n”,p,testbuf之后);
printf(“无模具!\n”);
}
汇编

gcc-maix64-o 1.c

结果

本地之前:1100014b8静态:1100014b8
自由本地后:1100014b8静态:1100014b8
不要死


您没有通过malloc/calloc等动态分配内存。为什么要释放全局数组?释放未通过
malloc
和friends分配的内存会导致未定义的行为(google that),其中包括“程序死亡”和“显然工作正常”@Trickzter:这是代码错误的一个简单示例。我不知道程序没有死掉,但我看了代码后才发现。@Jabberwocky:如果指针参数不是以前由malloc子系统分配的地址,或者指针参数已被释放,则会出现未定义的结果。(来自IBM:)“出现未定义的结果”->堆区域中的其他内存可以被删除吗?@HyungKyuShin不可以。这是未定义的行为。在最好的情况下,您的程序将崩溃,在最坏的情况下,程序将继续运行,但
malloc
free
使用的内部数据结构可能会损坏,这可能会导致程序中出现奇怪的错误。
#include <stdio.h>

char testbuf[512];
void main()
{
        char *p=NULL;
        p = testbuf;
        printf("before local:%llx static:%llx\n", p, testbuf);
        free(p);
        printf("after free local:%llx static:%llx\n", p, testbuf);
        printf("No Die.!\n");
}