Advertisement

Header files that call each other

Started by August 08, 2000 01:04 AM
4 comments, last by vbisme 24 years, 4 months ago
How do you guys explain header files that call on each other? Would it result in a infinate loop or just once?
Enclose all your headers with #ifndefs, like this:

Foo.h:

#ifndef FOO_H
#define FOO_H


#endif // FOO_H


That way, they will only be included once per compile.

Or, a VC++ specific solution is:

#pragma once
Advertisement
should it be

#ifninclude "foo.h"
#include "foo.h"
#endif

???

or not???
The technique Qoy specified is most widely used.

In the beginning of each header file:

#ifndef HEADERFILENAME_INCLUDED
#define HEADERFILENAME_INCLUDED

And in the end of the file:

#endif // HEADERFILENAME_INCLUDED
is it the " _ " (underscore) the significate here?
let''s say we have a file myHeader.h

#ifndef myHeader.h_INCLUDED
#def myHeader.h_INCLUDED
#endif
the underscore is not significant
you could just have

#ifndef MYFILE
#define MYFILE




#endif

but you generally use the filename so if your filename is myfile.h
you use
#ifnedf MYFILE_H
#define MYFILE_H



#endif

but it isnt required


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

This topic is closed to new replies.

Advertisement