Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include a header in another header file

Tags:

c

include

header

I've defined a struct item in a .h file. Now I'm defining another struct tPCB in another .h which is part of the same project, and I need the tPCB to have an item. I thought that just making part of the same TurboC project would allow me to use item in the other header file, but the compiler throws me "undefined type: ite".

I guess I somehow have to include the first header on the second one, However I have seen the same a similar code which works without doing so.

Is there any other way than just adding an #include line to make it work?

like image 441
bluehallu Avatar asked Mar 17 '11 19:03

bluehallu


1 Answers

If your .c #includes the two .h files in the proper order, it will work. That's probably what happened in the case you remember. The safest course is to #include every file that defines your dependencies, and rely on the include guards in each .h to keep things from being multiply defined.

like image 147
Mark Ransom Avatar answered Sep 17 '22 12:09

Mark Ransom