Alex Rivera | Logout

warning: ‘struct user_data_s’ declared inside parameter list

Asked 2009-11-12T03:15:46.267
26

I'm getting this error:

transform.c:23: warning: ‘struct user_data_s’ declared inside parameter list
transform.c:23: warning: its scope is only this definition or declaration, which is probably not what you want

Which I think is because I have a struct that contains a struct.

This is what I am trying to do:

void f2(struct user_data_s* data) {
  printf("Number %i\n", data->L);
}

void f1(struct user_data_s* data) {
  printf("Number %i\n", data->L);
  f2(data);
}

The printf in f1 works, but the line

void f2(struct user_data_s* data) {

gives the error.

Does anyone know how I can fix this?

c
Edit
Report

1 Answer

8

The compiler already gave you a pretty good explanation of what's going on.

You haven't declared struct user_data_s anywhere in advance. The compiler sees struct user_data_s in the above function definitions for the very first time ever. In each case the declaration of struct user_data_s has block scope, i.e. it is local to the corresponding function. This means that the first declaration of struct user_data_s in the f1 definition is completely unrelated the the second declaration of struct user_data_s in f2 definition. These declarations declare two completely different local (to each function) types struct user_data_s. You can't call f2 from f1 as in your example since their parameter types are completely unrelated.

Normally, you should have struct user_data_s declared at file scope in advance, instead of declaring it in function definition. Did you forget to include a header with the declaration of struct user_data_s by any chance?

answered 2009-11-12T03:19:52.673

Your Answer