Thread: implicit declaration

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    implicit declaration

    Hey guys i have a problem im trying to make a program that inserts a node but when im calling the function in my main i get an implicit declaration error.

    Any suggestions?

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    typedef struct ListNode * ListNodePtr;
    
    typedef struct ListNode
    {
      int data;
      ListNodePtr * next;
    
    
    }ListNode;
    
    int main (void)
    {
       int data;
       ListNodePtr root = NULL;
    
    
      if(!ListInsert(root, data))
      {
        printf("Insertion of node falied\n");
      } 
    
    
      return 0;
    }
    
    int ListInsert(ListNodePtr *head, int data)
    {
    
    
      return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Either define the function before you call it, or prototype it first.
    Code:
    void foo( void ); /* prorotype it */
    
    int main( void )
    {
        foo( ); /* call it */
        return 0;
    }
    
    /* define it */
    void foo( void )
    {
        ...whatever...
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Here ya go. One problem was you didn't prototype your function. Another was your if statement.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    typedef struct ListNode * ListNodePtr;
    typedef struct ListNode
    {
      int data;
      ListNodePtr * next;
    }ListNode;
    
    int ListInsert(ListNodePtr *head, int data);
    
    int main (void)
    {
       int data;
       ListNodePtr root = NULL;
    
    
      if(!ListInsert(&root, data))
      {
        printf("Insertion of node falied\n");
      } 
    
    
      return 0;
    }
    
    int ListInsert(ListNodePtr *head, int data)
    {
      return 0;
    }
    Edit: Argh... beaten to the punch.
    Sent from my iPadŽ

  4. #4
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    I thought it would b the prototype but wat do i pass to the parameters in the prototype of the function

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You pass nothing, infact you don't even have to declare variables to the parameters.

    You can prototype like this:
    Code:
    void function(float, float, char, float&, float&);
    Sent from my iPadŽ

  6. #6
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    ahhh kewl thanks for that got... i thought you still had to pass variables when prototyping

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by SlyMaelstrom
    You pass nothing, infact you don't even have to declare variables to the parameters.

    You can prototype like this:
    Code:
    void function(float, float, char, float&, float&);
    Except this prototype is C++ and not C.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Ooops, sorry, I forgot this was the C programming board.
    Sent from my iPadŽ

  9. #9
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by SlyMaelstrom
    You pass nothing, infact you don't even have to declare variables to the parameters.

    You can prototype like this:
    Code:
    void function(float, float, char, float&, float&);
    That's legal C++, not legal C. Perhaps you meant
    Code:
    void function(float, float, char, float *, float *);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM