On Mon, Jan 25, 2010 at 1:50 AM, Jimmy Johnson <[email protected]> wrote:
> Not sure what you mean by include guards?  Is this the "if not defined 
> include it" constructs?


#ifndef THIS_INCLUDE_FILE_H /* each header should use a unique name. */
#define THIS_INCLUDE_FILE_H
[... body of header file ...]
#endif

> If so then when I write a class I must do something like:
>
> if not defined GL then {include <GL.h> define GL?

No. The stuff in the header file does that for you. Simply #include it
if you need stuff from it.

> I'm not sure of the syntax yet, but if that is the process, then every class 
> I write
> will have to know that *I* am using the symbol "GL"?

The token being tested (as pointed out above) should be unique.
Typically the name of the header file is used somewhere in it.

<gl.h> is an openGL header, yes? So it is they who decide what the
token is, and you shouldn't need to worry about it.

> But let's say I am writing a class that may be used in many projects, 
> would/should I say at the top of my file something like:
> #define MYFILE_INCLUDED  // let users know that my header has been used and 
> they can check for this symbol MYFILE_INCLUDED?

Yes, but your users shouldn't have to care about it - it's only
purpose is to prevent the contents of your header file being parsed
more than once by the compiler, not for your users to detect whether
or not your file has been included yet :

#ifndef MYFILE_INCLUDED
#define MYFILE_INCLUDED
[header file]
#endif

Then your users can #include <myfile.h> as many times as they want
without the compiler complaining.


-- 
PJH

http://shabbleland.myminicity.com/
http://www.chavgangs.com/register.php?referer=9375
http://www.kongregate.com/?referrer=Shabble

Reply via email to