Use preprocessor in header

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bryan Parkoff

    Use preprocessor in header

    I plan to create a library when I complete the implementation in both
    header code and source code. I declare variable and function in header code
    and I define variable and function in source code.
    Do I truly need to use preprocessor if C Compiler does not need to
    recompile unmodified header code and source code? What about pragma? I
    often modify main.cpp to do more implementation while both Test.h and
    Test.cpp are seldom modified.

    For Example

    /* Test.h */

    #ifndef TEST_H
    #define TEST_H

    /* Declare global variable using extern or static */
    /* Declare global function */

    extern int a;
    void do_test (void);

    #endif /* TEST_H */

    /* Test.cpp */
    #include "Test.h"

    int a = 0;

    void do_test (void)
    {
    /* do something */
    }

    /* Main.cpp */
    #include "Test.h"

    int main (void)
    {
    do_test (void);

    return 0;
    }

    --

    Yours Truly,
    Bryan Parkoff


  • Thad Smith

    #2
    Re: Use preprocessor in header

    Bryan Parkoff wrote:
    I plan to create a library when I complete the implementation in both
    header code and source code. I declare variable and function in header code
    and I define variable and function in source code.
    Do I truly need to use preprocessor if C Compiler does not need to
    recompile unmodified header code and source code?
    Yes, if you want the compiler to include the header files.

    What about pragma?

    Yes, what about pragma?


    --
    Thad

    Comment

    • santosh

      #3
      Re: Use preprocessor in header

      Bryan Parkoff wrote:
      I plan to create a library when I complete the implementation in
      both
      header code and source code. I declare variable and function in
      header code and I define variable and function in source code.
      Do I truly need to use preprocessor if C Compiler does not need to
      recompile unmodified header code and source code?
      Some compilers have options for creating and using precompiled headers.
      Also you can skip the preprocessor stage in many compilers, but the
      details of how to do that are compiler specific. You'll need to ask in
      group for your compiler or platform.

      <snip>

      Comment

      Working...