Thread: warning: implicit declaration of function ‘malloc’

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    warning: implicit declaration of function ‘malloc’

    What do these warnings mean?

    Code:
    12.8.c: In function ‘insert’:
    12.8.c:29: warning: implicit declaration of function ‘malloc’
    12.8.c:29: warning: incompatible implicit declaration of built-in function ‘malloc’
    Code:
    #include <stdio.h>
    
    struct listnode {
    	int num;
    	struct listnode *nextPtr;
    };
    
    typedef struct listnode ListNode;
    
    void insert( ListNode **sPtr, int number );
    
    
    
    
    int main()
    {
    //	printf( "Hello, world\n" );
    	
    	return 0;
    }
    
    
    
    
    void insert( ListNode **sPtr, int number )
    {
    	ListNode *newPtr;
    
    	newPtr = malloc( sizeof( ListNode ) );
    
    	if ( newPtr != NULL ) {
    		printf( "hello" );
    	}
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    #include <stdlib.h>

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    182
    thanks

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It means you failed to include the proper header for the function you are trying to call. Don't let yourself be mislead by the compiler saying it's a warning; it's actually a very serious error.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  4. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM