Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: ‘struct user_data_s’ declared inside parameter list

Tags:

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?

like image 949
Louise Avatar asked Nov 12 '09 03:11

Louise


1 Answers

You have declared your struct in between (or possibly after) your declarations of f2 and f1. Move your struct declaration so that it comes before both declarations.

That is to say:

struct user_data_s {     int L; };  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); } 

compiles without errors, but

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

will not compile, because f2 has no way to know what a struct user_data_s is.

You might be used to programming in a higher-level language that lets you place your declarations/definitions pretty much anywhere (such as C# or Python), but unfortunately, C is compiled strictly top-to-bottom.

like image 116
Mark Rushakoff Avatar answered Sep 22 '22 12:09

Mark Rushakoff