Preprocessor Wraper

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

    Preprocessor Wraper

    I am curious. How can you reproduce compiler error if preprocessor
    wraper is not omited. It may cause to include a copy of header twice or
    more. Please write a short sample code like this.

    //Test.h
    //#ifndef TEST_H
    //#define TEST_H

    class A
    {
    public:
    void run( void );

    private:
    int x;
    int y;
    };

    //endif // TEST_H

    --

    Yours Truly,
    Bryan Parkoff


  • Mirco Wahab

    #2
    Re: Preprocessor Wraper

    Bryan Parkoff wrote:
    I am curious. How can you reproduce compiler error if preprocessor
    wraper is not omited. It may cause to include a copy of header twice or
    more. Please write a short sample code like this.
    >
    //Test.h
    [snipped]
    What is that good for? What would be wrong with
    a solution like this one? ==>

    // Test.h
    //#ifndef TEST_H
    //#define TEST_H

    class A {
    // ...
    // ...
    };

    #ifndef TEST_H
    #error preprocessor wraper is omited
    #endif


    //#else
    // #error hehe TEST_H included alot
    //#endif // TEST_H

    <==

    Regards

    M.

    Comment

    • James Kanze

      #3
      Re: Preprocessor Wraper

      On Jun 10, 10:44 pm, Mirco Wahab <wa...@chemie.u ni-halle.dewrote:
      Bryan Parkoff wrote:
      I am curious. How can you reproduce compiler error if
      preprocessor wraper is not omited. It may cause to include
      a copy of header twice or more. Please write a short sample
      code like this.
      //Test.h
      [snipped]
      What is that good for?
      You might want to add something like that to your test suite.
      Of course, it's pretty easy to do, just include the header twice
      in one of your test programs.

      (I'll admit that I've never done so. But of course, in any
      reasonable environment, the include guards are generated
      automatically by the editor when you create the file.)

      --
      James Kanze (GABI Software) email:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      Working...