theunknownsolider
theunknownsolider

Reputation: 23

C Undeclared (first use in this function)

I am getting this weird error:

app_server.c: In function ‘wasFeedRead’:
app_server.c:269:14: error: ‘tmp’ undeclared (first use in this function)
     readers* tmp;
              ^
app_server.c:269:14: note: each undeclared identifier is reported only once for each function it appears in

My wasFeedRead Function is just containing this few lines:

int wasFeedRead(char* loginName, readers* readers){
    readers* tmp;
    return 0;
}

Reader was defined in the following way:

struct readers {
    char *user;
    struct readers *next;
};
typedef struct readers readers;

The Error is in the readers* tmp; line and not in the int wasFeedRead(char* loginName, readers* readers) line so the declaration of readers should be right..

Im really frustrated with this error, does anyone know how to fix this? I already tried to change the Var. Name but that didnt change anything (Suprise Suprise).
Thanks in advance

Upvotes: 0

Views: 7353

Answers (2)

Jerônimo Nunes
Jerônimo Nunes

Reputation: 91

The parameter name is shaddowing the type name inside the function body. It could be resolved by renaming the type or the parameter name.

Example:

struct readers {
    char *user;
    struct readers *next;
};
typedef struct readers Readers;

here the type is Readers and then it wont collide with readers that is the name of the parameter.

int wasFeedRead(char* loginName, Readers* readers){
    Readers* tmp;
    return 0;
}

Upvotes: 0

Vlad from Moscow
Vlad from Moscow

Reputation: 310910

The function parameter name readers hides the type name readers

int wasFeedRead(char* loginName, readers* readers){
    readers* tmp;
    return 0;
}

So within the function the name readers is considered as a variable. Use some else name for the parameter.

Or use the elaborated type name in the declaration

    struct readers* tmp;

Upvotes: 4

Related Questions