1 Attachment(s)
'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 .
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));
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
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 :)