Languages/C/SplitCH

From UIT
Revision as of 14:15, 10 December 2013 by Pim (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Source and header file split

It is sometimes complicated to split the header and the source file, here are some hints:

  • The header MUST contain what is necessary from the outside of the source file.
  • The header SHOULD NOT contain, what is not necessary.
    • There is no reason to pollute the namespace of the whole project.
    • Keeping the interface small and as clean as possible will make team work simpler.
  • The header file MUST prevent multiple inclusion
  • A header file SHOULD be complete (it defines or includes all it needs).
    • Example, if you use a uint32_t parameter in a function, the header should include <stdint.h>
  • A header file SHOULD not include files only used in source file
  • The header SHOULD be commented enough so there is no need to open the source file.
  • The source file MUST include the header
    • This will ensure constistency

Temperature sensor example

Here is a simple main :

#include <stdio.h>
#
Personal tools
Namespaces
Variants
Actions
Navigation
Browse
Toolbox