Malloc warning

This is a discussion on Malloc warning within the C Programming forums, part of the General Programming Boards category; I am getting an implicit declaration warning of the malloc function. What is wrong here. Code: void StackInit(stackST *stackP) { ...

  1. #1
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151

    Post Malloc warning

    I am getting an implicit declaration warning of the malloc function. What is wrong here.


    Code:
    void StackInit(stackST *stackP)
    {
      stackElement *newContents;
    
      /* Allocate a new array to hold the contents. */
    
      newContents = (stackElement *)malloc(sizeof(stackElement) * 10);
    
      stackP->contents = newContents;
      stackP->lineST = 0;
      stackP->top = -1;  /* I.e., empty */
    }
    Please reply.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,657
    Stop casting malloc and #include stdlib.h to get the proper prototype.

  3. #3
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151
    Thanks, thats fixed it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21