简体   繁体   中英

Header guards and redefenitions issues in c

I have a project with 3 files and I am quite confused as to what's the proper include order and what header guards are needed to avoid redefinition issues. Lets call the files ac, ah, bcbh, cc, ch There are functions I need in all 3 of the files so I am not sure where to put them in a way it won't cause redefinition. ah is the main file - and it has includes to bh and chbh and ch don't include one another. How to solve this? Where do I add header guards and do I add them on the entire header file or only on the section in the header files that exists in other header files that include this one? (I mean - I think I mustn't add header guards on the unique parts of the header file - that don't exist in the pother header files that include it).

look up include guards it goes like

#ifndef A.H
#define A.H

"your code"

#endif

the name you choose for your guard does not matter.

alternative you can just use #prama once

on top of your program it is widely supported.

I would say you should try to understand the hierarch y of included headers if you can. confusion is bad

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