Sign in to follow this  

Simple Question - #include macro

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any variation between including a *.cpp file and including a *.h file? And how does include work, or act? Does the preprocessor just add in the text at that spot, or does it do something else?

Share this post


Link to post
Share on other sites
first you shouldnt include a cpp file

#include <foo.h>

is removed from the file by the preprocessor and is replaced be the contents of foo.h (this is not saved to the file only done while compiling)

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
first you shouldnt include a cpp file

#include <foo.h>

is removed from the file be the preprocessor and is replaved be the contents of foo.h (this is not saved to the file only done while compiling)


Quote:
Original post by ace_lovegrove
As far as i know it simply inserts the code at that spot. So including a CPP would be less efficient for compilation that H.

ace


If the file is not part of the current project - it does not matter. You could #include "foo.thisisadumlongname" and it would work as long as you follow the correct syntax inside the file - ie it IS a .h filer just not named that way. Its contents are pasted in place of the #include.

However - if the .cpp file IS part of the project (added to the projects workspace), than including it is bad because .cpp files are compiled by default - so you would be deouble compiling it - making linker erros pop up.

I would reccomend using the traditional .h files and .cpp files. It just makes life easier [smile].

- Drew

Share this post


Link to post
Share on other sites
The preprocessor just substitutes the directive with the (preprocessed) contents of the file. It doesn't care about the file's name or extension (if any!), nor even about it's contents (aside from the fact that those contents will too be run through the preprocessor).

It doesn't even have to be C or C++ code at all: the C preprocessor is to C what a food processor is to food.

Share this post


Link to post
Share on other sites

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this