Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for existence of header file inclusion?

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
0
0
US
I have a class that inherits from CListBox where I override some of the default drawing and whatnot.

This class currently requires ProfUIS headers to be used with the application ( #include <Prof-UIS.h> ).

Is there anyway that I can make a compiler directive to check for that file inclusion to use one set of code, and if it's not included to use another set of code? This would allow the class to become disconnected from the Prof-UIS stuff, but still use it if it's available.

I'm still a newb at VC++ when it comes to directives and basically anything with a # in front of it.

Thanks for the help.
 
All properly written header files should do that automatically:
Code:
#ifndef SOME_LONG_UNIQUE_STRING_OF_CHARS_AND_NUMBERS
#define SOME_LONG_UNIQUE_STRING_OF_CHARS_AND_NUMBERS

// Header stuff goes here.

#endif // SOME_LONG_UNIQUE_STRING_OF_CHARS_AND_NUMBERS
 
I don't normally use the long sequence: just the filename, replacing the . with an _

What I would do is wrap #include <Prof-UIS.h> into another include file. I don't know if Prof-UIS.h uses the #ifndef technique. Something like

useprofuis.h
Code:
#ifndef useprofuis_h
#define useprofuis_h
#include <Prof_UIS.h>
#endif
janus.h
Code:
#ifndef janus_h
#define janus_h
#ifndef useprofuis_h
#include <something_else.h>
#endif
#endif
 
Yeah, that's usually what I do too since I'm lazy; but I can imagine very large projects having some files in different directories with the same name...
 
That's rather sloppy. You might want to create an internal standard where the first two letters of the file name are a code for the project or directory.

If you should have Unix and Windows users sharing projects, you'll also want to tell the Unix guys and girls not to name their files with alternate case variants of existing files.
 
or you can use a format like:
#define HEADER_FILENAME_DATE_TIME
Since it's highly unlikely that two header files with the same name would be created at the exact same time, that should guarantee the macro name to be unique.
 
Using date/time is just as bad as the MS autogenerated defines with built in GUIDs.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top