Take the 2-minute tour ×

Possible Duplicate:
#include all .cpp files into a single compilation unit?

I'm working on a project in MSVS where most implementation files (.cpp) are excluded from the build and included in a single source file that is compiled.

#include "b.cpp"
#include "c.cpp"
//and so on...

And since b.cpp and c.cpp aren't compiled by themselves, this is OK.

I know this is not standard practice, I know the pitfalls and I probably wouldn't do this (unless of course someone comes up with a good reason).

So the question is - what's the use of this technique? Does it make compilation faster (also consider a distributed compilation environment)?

share|improve this question
add comment

marked as duplicate by BЈовић, Luc Touraille, Praetorian, Mark Ransom, GManNickG Jul 25 '12 at 18:04


2 Answers

up vote 3 down vote accepted

This is called a unity build.

It's supposed to speed up compilation of the source code.

See a related question here that provides more details: (c++) The benefits / disadvantages of unity builds?

share|improve this answer
add comment

The other point can be that some implementation files can be autogenerated. It is much easier to autogenerate an entire file than dealing with changes injection into the existing code. Like partial classes in C#.

share|improve this answer
In such cases I would use a different extension than .cpp, but this is a good point. –  Mark Ransom Jul 25 '12 at 18:00
add comment
