Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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
C “的冲突类型”;“免费”;_C_Free - Fatal编程技术网

C “的冲突类型”;“免费”;

C “的冲突类型”;“免费”;,c,free,C,Free,我发现了错误 “free”的冲突类型 在调用下面的free()函数时 int main ( ) { char fx [] = "x^2+5*x-1"; node * fxNode = buildTree(fx, sizeof(fx)/sizeof(char)); printf(deriveFromTree(fxNode)); // Should print "2*x+5" free(fxNode); return 0; } 不知道为什么。不确定这件事是否

我发现了错误

“free”的冲突类型

在调用下面的
free()
函数时

int main ( )
{
    char fx [] = "x^2+5*x-1";
    node * fxNode = buildTree(fx, sizeof(fx)/sizeof(char));
    printf(deriveFromTree(fxNode)); // Should print "2*x+5"
    free(fxNode);
    return 0;
}
不知道为什么。不确定这件事是否重要,但最重要的是

#include <stdio.h>

char opstack [5] = {'+','-','*','^', '\0'};

unsigned short int lowerOpPrecedence ( char, char, char * );

int stringToUnsignedInt ( char *, unsigned int * );
int stringToDouble ( char * , double * );
unsigned short int stringCompare ( char * , char * );
void stringCopy ( char * , char * );

typedef struct treeNode
{
    char * fx;
    char * op;
    struct treeNode * gx;
    struct treeNode * hx;
} node;


unsigned short int getNodeState ( node * );
node * buildTree ( char *, int );
char * basicDerivative ( char * );
char * derivateFromTree ( node * );
#包括
char opstack[5]={'+','-','*','^','\0'};
无符号短整数优先(字符,字符,字符*);
int stringToUnsignedInt(字符*,无符号整数*);
int stringToDouble(char*,double*);
无符号短整型字符串比较(char*,char*);
无效字符串副本(字符*,字符*);
类型定义结构树节点
{
char*fx;
char*op;
结构树节点*gx;
结构树节点*hx;
}节点;
无符号短整数getNodeState(node*);
节点*buildTree(char*,int);
字符*基本派生(字符*);
char*派生fromtree(节点*);
下面是一组函数实现

您需要添加
#include
免费()提供原型


另外,如果链接器命令文件包含堆的特定定义,包括起始地址处的标签和长度标签,则
main()
的建议签名为
int main(void)

然后您可以编写自己的malloc、free、realloc、calloc等版本


顺便说一句:代码正在调用“free()”,内存分配是如何进行的,而“free()”将返回到堆中?

您可以在一些操作系统内存原语(修改内存原语)之上实现
malloc
free
,比如(在Linux上)和
munmap
。详细信息是特定于操作系统的

顺便说一句,如果您的目标是只使用
编写一个程序,那么它的大多数实现都在内部使用
malloc
,因为每个
文件中的缓冲区通常是一些动态分配的字节区域(具体来说,它通常是通过
malloc
分配的)。换句话说,
fopen
的实现很可能使用
malloc
;另见。因此,如果您接受包含
,您应该接受包含

请注意,有几个(又称libc
)是:;您可以研究并改进GNU或的源代码


另请参见相关问题。

Dang it。我正试图从头开始编写一个程序——除了
,没有库。我有没有办法从头开始实现一个
免费的
函数?@firedfromfrommicrosoft
不是一个库,而是一个头文件。如果不想包含头文件,可以在源代码中添加转发声明。从头开始编写
free
听起来像是重新发明轮子。为什么要这样做?@firedfromfmicrosoft Using
free()
意味着您可能也在使用
malloc()
calloc()
,这两个都在
中定义。未能包含此头文件可能会导致灾难性的错误。如果您的代码要使用“free()”,则它还需要访问“malloc()”函数族。试图在不使用相关库的情况下编写程序是徒劳的。一个编程目标是重新利用以前的成果,而不是“重新发明轮子”。也就是说,图书馆是你的朋友。