Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflicting types for "free"

Tags:

c

free

I'm getting the error

Conflicting types for 'free'

on the call to free() function below.

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;
}

Can't figure out why. Not sure if this matter, but what's above it is

#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 * );

and what's below it is a bunch of function implementations.

like image 211
Fired from Microsoft Avatar asked Dec 14 '22 14:12

Fired from Microsoft


1 Answers

You need to add #include <stdlib.h> to provide the prototype for free().

Also, the recommended signature for main() is int main (void).

like image 151
Sourav Ghosh Avatar answered Dec 28 '22 07:12

Sourav Ghosh