简体   繁体   中英

C Passing an array of structures, array type has incomplete element type

I am writing a small web router. I wanted to write a generic function called findRoute that would accept a string as the route name and an array of structures to search through.

router.c

struct route 
{
   char *routeName;
   int routeId;
};
int findRoute(char find[], struct route list[])
{
   // do some strcmp 
   // return id of found route
}

It would be used like this

subRouter.c

enum someRoutes
{
  Route1,
  Route2
};
struct route someRoute[] = {
   {"route1", Route1},
   {"route2", Route2}
}
int routeId = findRoute("route1", someRoute);
switch(routeId){
   //etc
}

I am getting the error array type has incomplete element type but only in my H file which simply looks like

router.h

int findRoute(char find[], struct route list[]);

My guess was I am not giving a size to the list parameter, but it doesn't seem to matter when I do.

Move the struct route definition from router.c to the header:

router.h:

struct route 
{
   char *routeName;
   int routeId;
};

And include router.h in subRouter.c .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM