Advertisement

excluding header files when appropriate

Started by August 11, 2000 01:04 AM
1 comment, last by Joker2000 24 years, 4 months ago
I have recently broken my program up into many seperate files and have since noticed a problem. Occasionally, header files that have already been included are included again. If you include two header files that are the same, will the compiler be smart enough to omit one of them? For example: Think of this as File1.cpp/h.

*** FILE1.CPP ***
#include 
#include "file1.h"

*** FILE1.H ***
#include "file2.h"
 
Here''s File2.cpp/h.

*** FILE2.CPP ***
#include 
#include "file2.h"

*** FILE2.H ***
#include "file1.h"
 
Please excuse the crudeness of the example, but just notice that File1.h calls File2.h, and then File2.h calls File1.h in return. Will this cause any code bloat or anything bad? --- Joker2000 Stevie Ray Vaughan - The Legend
inside every header file you should have:

#ifndef NAME_H // replace NAME appropriately#define NAME_H// EVERYTHING GOES IN HERE!!#endif  


this will stop multiple inclusions.

-----------------------------
-cow_in_the_well

http://cowswell.gda.ods.org/


"If it's stupid but works, it's not stupid" - Murphey's Law

Edited by - cow_in_the_well on August 11, 2000 2:14:59 AM

- Thomas Cowellwebsite | journal | engine video

Advertisement
Or you can try adding

#pragma once

to the top of each file...

I use the method cow mentioned, so I''m not really sure if there''s any real disadvantages to using this method. The other way might just be better for cross-complier compatibility or something.

===========================================
As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality.

-Albert Einstein

This topic is closed to new replies.

Advertisement