Tag: 自由

我可以使用哪些免费工具生成c代码的程序依赖图

我想从C源代码生成程序依赖图(PDG)。 我找到了解释它是怎么做的论文,但都使用了商业CodeSurfer工具。 有没有可以完成这项工作的免费工具或开源项目?

C – 指针在释放后不为空

释放后指针的值是否变为NULL? int* p = malloc(sizeof(*p)); free(p); if(p==NULL) printf(“Null\n”); else printf(“Not null\n”); 输出: Not null 好吧,我假设没有; 无论如何,我今天早些时候提出了一个问题: 在这里查看: C – 如何释放动态分配的内存? List* head1 = NULL; insertFront(&head1, 1); insertFront(&head1, 2); print(head1); while (head1) { List *temp = head1; head1 = head1->next; free(temp); } if(head1 == NULL) printf(“Null\n”); else printf(“Not null\n”); 这种情况下的输出: Null 在这种情况下,在释放head1(节点也)后,head1变为null,不是吗? 最后,我错过了一些概念吗? head1为null,但p不是。 我的问题是: 为什么head1和p之间的值不同?

我可以在C中释放()静态和自动变量吗?

代码如下: #include int num = 3; // Static external variable int *ptr = # int main(void) { int num2 = 4; // Automatic variable int *ptr2 = &num2; free(ptr); //Free static variable free(ptr2); //Free automatic variable return 0; } 我尝试编译上面的代码,它的工作原理,我很好奇free()函数是否能够释放静态变量和自动变量? 或者基本上什么也没做?

退出前我应该释放内存吗?

因错误而退出程序时,我应该释放所有我的mallocated内存吗? something = (char**) malloc (x * sizeof(char*)); for (i = 0; i < x; i++) something[i] = (char*) malloc (y + 1); … if (anything == NULL) { printf("Your input is wrong!"); // should I free memory of every mallocated entity now? exit(1); } else { // work with mallocated entities … free(something); // […]