c - enum declaration in header file -
i have files a.c , b.c , b.h . in a.c there
enum cmd{ first, second, third, }; and later in file there is
bool function(...){ //... enum cmd data_type = first; //... } in file b.c need use
if (data_type == first){...} i tried include in b.h this:
extern enum cmd data_type; and included #include "b.h" in a.c , b.c . files in propper folders of project. no cigar :( line in b.c gives this:
20: identifier "from_sms" undefined 70: incomplete type not allowed how make work. a.c file writen else , i'm modifiing code b.c . original code mess , wan fidlle less possible :) architecture ie stm32 , i'm using uvision 3 ide.
thank you
an enum type, should put in in .h.
extern keyword variables.
edit: sorry, had badly read code.
here problem try use enum without having defined. think when compiler compiles something, takes every .c file separately, , "copies" content of include c file.
so here have b.c includes b.h since declaration of type in a.c, compiler has no way of knowing it, hence throwing error when trying compile b.c.
to solve it, declare type @ top of b.h , include in both files, or create "myenum.h" file include in .h / .c files require it.
Comments
Post a Comment