Conflicting types for "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] = {'+','-','*','^', ''}; 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.

-------------Problems Reply------------

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

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

You could implement your malloc and free above some operating system memory address space primitives (modifying the virtual memory of your process), like (on Linux) mmap(2) and munmap. Details are operating system specific.

BTW, if your goal is to write a program using only <stdio.h> most implementations of it are internally using malloc, since the buffer inside every FILE is generally some dynamically allocated byte zone (so concretely, it is generally allocated thru malloc). In other words, the implementation of fopen very probably uses malloc; see also this. Hence if you accept to include <stdio.h> you should accept to include <stdlib.h>...

Notice that several standard C libraries (a.k.a. libc) are free software; you could study -and improve- the source code of GNU glibc or of musl-libc.

See also this answer to a related question.

if your linker command file contains a specific definition of the heap, including a label at the start address and a length label,

then you could write your own version of malloc, free, realloc, calloc, etc.

BTW: the code is calling 'free()' How was that memory allocation made that 'free()' will be returning to the heap?

Category:c# Views:1 Time:2018-03-31

Related post

  • Why do I get a "conflicting types for getline" error when compiling the longest line example in chapter 1 of K&R2? 2012-01-06

    Here is a program I'm trying to run straight from section 1.9 of "The C Programming Language". #include <stdio.h> #define MAXLINE 1000 int getline(char line[], int maxline); void copy(char to[], char from[]); main() { int len; int max; char lin

  • What does error conflicting types for '' mean? 2009-07-21

    i got an error that said "error: conflicting types for '____'. What does that mean? --------------Solutions------------- Quickfix: Make sure that your functions are declared once and only once before they are called. For example, change: main(){ myfu

  • Getting "conflicting types for function" in C, why? 2009-10-11

    I'm using the below code: char dest[5]; char src[5] = "test"; printf("String: %s\n", do_something(dest, src)); char *do_something(char *dest, const char *src) { return dest; } The implementation of do_something is not important here. When I try to co

  • conflicting types for '-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row' 2010-09-11

    I have this code: - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { if ([[tableColumn identifier] isEqualToString:@"friend name"]) { if (row == 0) { return @"All friends"; } else { return [

  • gcc Error: "Inputtools.c:85: error: conflicting types for 'strcasestr'" 2010-09-27

    I tried compiling ADPACK, written in C, on an Intel Mac running OX 10.6.4. I got the following error from the make command. gcc -I/usr/local/include -I/home/ozaki/include -c adpack.c adpack.c: In function ‘main’: adpack.c:223: warning: incompatible i

  • Obj-C "Conflicting types for/ Previous declaration of" errors 2011-06-28

    Obj-C beginner, I'm getting "Conflicting types for.../ Previous declaration of..." errors on the following lines of the implementation file: -(void) setWidth: (double) w andHeight: (double) h -(double) area -(double) perimeter Here's the .h and .m: #

  • Error in c programme conflicting types for xx and previous implicit declaration of xx was here 2012-01-15

    Suppose I have a file insert.c in which two functions are defined: 1.insert_after 2.insert_before The definitions of these func are something like this: insert_after(arg1) { if(condition 1) { ......... } else insert_before(arg1); } insert_before(arg)

  • Resolving conflicting type for functions with the same name in two external libraries 2012-01-18

    I have included the following libraries into my code. #include <minix/drivers.h> #include <curl/curl.h> #include <sys/stat.h> #include <time.h> #include <assert.h> #include <string.h> Now I get the following error:

  • C conflicting types for function with different arguments 2012-02-04

    I have a struct with 2 initialiser functions which take different types of arguments: struct myStruct; typedef struct myStruct *myStruct; INFNumber *myStructMake(long long arg); INFNumber *myStructMake(char *arg); I get a conflicting types for 'myStr

  • error: conflicting types for 'f' and previous declaration of 'f' was here 2012-02-17

    This code is just a situation that I found in my actual code which is very big so I'm giving in this code the structure "struct node" is not defined it is defined in another c source file. my c source code: /* test.c */ 1 #include<stdio.

  • Conflicting types for '-(bool)validateToolbarItem:(NSToolbarItem *)theItem' 2012-02-23

    I have this code: - (BOOL) validateToolbarItem:(NSToolbarItem *)theItem { BOOL enable = NO; if (1 == [theItem tag]) { enable = YES; } return enable; } And I get this warning, although the program runs as expected: Conflicting types for '-(bool)valida

  • Error: conflicting types for 'strlen' 2011-04-16

    I have a program, but I get an error message. Please help me on this. #include <stdio.h> #include <string.h> int print_strlen(char s[]); main() { char s[20]; printf("Enter the string:\n"); scanf("%s\n", s); } int print_strlen(char s[]) {

  • Conflicting types for function and a cast warning? 2012-02-19

    I'm sure this is an easy answer for someone with experience with pointers in c, but I am struggling at the moment to see my error. I get a warning that the return call from a function makes a pointer from integer, even though the return type of the f

  • What functionality do you get for free with Functors or other type-classes? 2012-01-09

    I read an article which said: Providing instances for the many standard type-classes [Functors] will immediately give you a lot of functionality for practically free My question is: what is this functionality that you get for free (for functors or ot

  • conflict type error previous declaration ___ was here 2011-02-24

    #define TRIP 6 #include <stdio.h> char error_area(char area_code, char S, char M, char L, char N, char P, char K, char R, char C, char U, char W, char O, char T, char F); int main(void) { char area_code, S, M, L, N, P, K, R, C, U, W, O, T, F, c

  • Compiling C code with conflicting types 2009-09-28

    I'm coding a program that uses ossp-uuid which defines a type called uuid_t. Now, the problem that I have is that this type is already defined in Mac OSX in the file unistd.h. So, the error I get is: /opt/local/include/ossp/uuid.h:94: error: conflict

  • How can I get rid of this conflict type warning? 2009-11-10

    Objective-C Conflict types for '-(NSInteger)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth' How can I get rid of this warning? .m #import "MyAppDataController.h" #import "MyApplicationData.h" @implementation MyAppDataController @synthe

  • Why do I get a "conflicting type" warning when I implement didSelectRowAtIndexPath: 2009-11-24

    I'm implementing the didSelectRowAtIndexPath: method in a tableviecontroller implementation. I get a "conflicting type" warning in my code. Everything seems to work, but the warning bugs me. The code in my implementation file is as follows. - (void *

  • C warning conflicting types 2010-03-12

    my code is void doc(){ //mycode return; } my warning is conflicting types for 'doc' can anybody solve it. --------------Solutions------------- In C, if you don't have a prototype for a function when you call it, it is assumed to return an int and to

  • Conflicting types in a 2D array (C) 2010-07-25

    I am making my first C program, and it utilizes a 2D array, and the code seems weird to me. First, why do I have to store "White" in [1][6]? I tried [0][6], but the compiler complains and won't run but when I call it in printf, it's [0][6]. Also, whe

  • Why am I getting a "Conflicting types" warning on the below instance method? 2010-08-06

    I have the below code - (UITableViewCell *)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [[cell textLabel] setFont:[UIFont systemFontOfSize:10.0]]; return cell; } For some reas

  • I'm getting a "conflicting types" error in C 2010-09-18

    I'm currently working on a program for a C course in which I have to output the area of a shape. Here is a function for a rectangle's area that I have in my program: double rectangle() // calculate area of rectangle { double length, width; printf("\n

  • Conflicting types - Function 2011-03-11

    The following code leads to "Conflicting types for 'testf'". Does anybody have an idea? .h: #import <UIKit/UIKit.h> @interface RootViewController : UITableViewController { } @end .m: #import "RootViewController.h" @implementation RootViewContro

  • conflicting types error when compiling c program using gcc 2011-04-17

    I tried to compile following program with gcc. 0 #include <stdio.h> 1 2 main () 3 4 { 5 char my_string[] = "hello there"; 6 7 my_print (my_string); 8 my_print2 (my_string); 9} 10 11 void my_print (char *string) 12 { 13 printf ("The string is %s

  • Conflicting types Warning when passing String to function in C 2011-04-27

    I haven't programmed in C for awhile and having an issue with passing a string to a function. The code works however I get warnings from gcc. I call the function in my main with: copyToCode(code, section1, section2); The function is: void copyToCode

Copyright (C), All Rights Reserved.

processed in 0.131 (s). 11 q(s)