What's the benefit for a C source file include its own header file -


i understand if source file need reference functions other file needs include header file, don't understand why source file include own header file. content in header file being copied , pasted source file function declarations in per-processing time. source file include own header file, such "declaration" doesn't seem necessary me, in fact, project still compile , link no problem after remove header it's source file, what's reason source file include own header?

the main benefit having compiler verify consistency of header , implementation. because convenient, not because required. may possible project compile , run correctly without such inclusion, complicates maintenance of project in long run.

if file not include own header, can accidentally in situation when forward declaration of function not match definition of function - perhaps because added or removed parameter, , forgot update header. when happens, code relying on function mismatch still compile, call result in undefined behavior. better have compiler catch error, happens automatically when source file includes own header.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -