'NODE' undeclared (first use in this function)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: 'NODE' undeclared (first use in this function)

  1. #1
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    'NODE' undeclared (first use in this function)

    I am developing a double linked list in C ( development environment ) is QT with mingw32 4.7 gcc / g++ compiler ,

    in the header file I have defined struct as follows
    Code:
    #ifndef LINKEDLIST_H
    #define LINKEDLIST_H
    
    
    #include <stdlib.h>
    #include <sys/stat.h>
    #include <signal.h>
    #ifndef NULL
    #define NULL 0
    #endif
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    /* Function code goees here  */
    
    struct NODE
    {
        char val;
        int  pos;
        struct NODE *previous, *next;
    };
    
    struct NODE *CreateList();
    
    #ifdef __cplusplus
    }
    #endif
    
    
    #endif // LINKEDLIST_H
    and C file

    Code:
    #include "LinkedList.h"
    
    struct NODE *CreateList()
    {
        struct NODE *node;
        node = (NODE *)malloc(sizeof(NODE));
        if(node == NULL){
            return NULL;
        }
        node->pos =0;
        node->previous = NULL;
        node->next = NULL;
        return node;
    }
    when compiling I am getting the following error
    'NODE' undeclared (first use in this function)

    and

    each undeclared identifier is reported only once for each function it appears in

    I have also attached the screen shot from the QT IDE

    look's like the compiler is not able to pick up the definition of NODE structure
    same happens in Netbeans IDE , interesting thing is if change the source file from c to cpp the error goes away .
    Any help would be much appreciated .
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,355

    Re: 'NODE' undeclared (first use in this function)

    You don't seem to have an appropriate typedef, so NODE should be struct NODE, which you got right quite a few times but failed to do so on this line:
    Code:
    node = (NODE *)malloc(sizeof(NODE));
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: 'NODE' undeclared (first use in this function)

    Hi Laserlight , in the line above it is declared as struct NODE node , what i want to draw your attention to is problem seems to be solved when I add
    Code:
    struct NODE
    {
        char val;
        int  pos;
        struct NODE *previous, *next;
    };
    
    typedef struct NODE NODES;
    I rather not do this, cause C way of compelling programmer to use struct key work makes the code more readable , I know in C++ it does not matter
    any help in this regard would be much appreciated
    Last edited by aamir121a; April 2nd, 2013 at 04:55 AM.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,355

    Re: 'NODE' undeclared (first use in this function)

    Quote Originally Posted by aamir121a
    I rather not do this, cause C way of compelling programmer to use struct key work makes the code more readable
    If you would rather not have the typedef because you think struct NODE is more readable, then write struct NODE instead of NODE, which is what I told you that you were missing in my previous post. I even showed you the line in which you wrote NODE instead of struct NODE. If you still cannot find and fix that, then I daresay that your claim that struct NODE is more readable than NODE has been disproved by yourself
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center