468,249 Members | 1,467 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

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
Jun 27 '08 #1
2 935
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.
Jun 27 '08 #2
On Jun 10, 10:44 pm, Mirco Wahab <wa...@chemie.uni-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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

205 posts views Thread by Jeremy Siek | last post: by
24 posts views Thread by Nudge | last post: by
16 posts views Thread by Trying_Harder | last post: by
18 posts views Thread by /* frank */ | last post: by
13 posts views Thread by Chris Croughton | last post: by
9 posts views Thread by Walter Roberson | last post: by
31 posts views Thread by Sam of California | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.