【发布时间】:2015-02-18 01:55:44
【问题描述】:
我在 ubuntu 上使用 ECLIPSE IDE 我编写了简单的代码来创建树头。 代码编译成功。但是在调试时,它会在执行 malloc 语句时出错。
错误
在“/build/buildd/glibc-2.19/malloc/malloc.c”中找不到源文件 找到文件或编辑源查找路径以包含其位置。
/*
* tree.c
*
* Created on: 04-Dec-2014
* Author: etron
*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
{
int key_value;
struct node *right;
struct node *left;
};
struct node *root=0;
struct node* insert(int key,struct node **leaf)
{
if(*leaf == 0)
{
*leaf = (struct node*) malloc(sizeof(struct node));
(*leaf)->key_value = key;
(*leaf)->left = 0;
(*leaf)->right = 0;
return 0;
}
}
void main()
{
struct node *bt=0;
int i=100;
insert(i,&bt);
}
【问题讨论】:
-
如果删除
malloc头文件,编译器是否显示任何错误消息? -
调试到 malloc 并没有什么收获。只是不要尝试进入 malloc。你的主线错了。
int main(void)。并且不要强制转换 malloc 的返回值。启用并注意编译器警告。它会抱怨你没有从插入返回。malloc由stdlib.h声明。为什么包括malloc.h? -
IMO,如果您不希望调试器出错,您应该剥离 glibc,或者提供可用的源文件。
-
我试过没有
它给出了同样的错误。 int main 没有进行任何更改,也尝试过不进行 malloc 类型转换,但在到达 malloc() 语句时进入执行时仍然出现错误。 -
@DavidHeffernan 谢谢先生,它与 step Over Run 一起工作
标签: c linux eclipse ubuntu malloc