Large multiple file programs |
When using
For any
Similarly,
For any
As a consequence of these principles, the compilation process for large projects is easy to understand: the programmer should just make sure to carefully include the correct include files for every individual file in the project. The compiler will then take care of determining the various dependencies and compiling the files in the project in the right order and in parallel whenever possible.
Notice that these rules are not satisfied in several other
programming languages such as C or C++: in this case, there is usually
a makefile for the project which describes the dependencies
and all kinds of compiler and linker flags which are necessary for
building the executable.
In the case when some of the functionality of a
Other files can be included into a given
When including a file a.mmx into the file b.mmx using
|
all public functions, classes and categories from the file
Public inclusions thus induce a dependency of b.mmx on a.mmx as well as of c_n.mmx on a.mmx for any file c.mmx which indirectly includes b.mmx. When building a large project in parallel, this means that both b.mmx and c.mmx will have to be recompiled whenever a change occurs in the public interface of a.mmx.
In order to reduce the number of dependencies inside a large project, it is possible to use the mechanism of private inclusions whenever appropriate. When including a file a.mmx into the file b.mmx using
|
all public functions, classes and categories from the file
In summary, a private inclusion of a.mmx in b.mmx still induces a dependency of b.mmx on a.mmx, but the transitivity of the inclusion relation is broken.
When using the mechanism of private inclusion, we still introduce dependencies for the build process: whenever the public interface of the included file a.mmx changes, the file b.mmx where the inclusion occurred needs to be recompiled.
On some occasions, none of the functionality of a.mmx is actually needed in b.mmx or any other file which includes b.mmx (directly or indirectly). Indeed, it may happen that we just want to ensure that some initialization code present in a.mmx is executed before we start executing b.mmx. For instance, the file a.mmx might initialize some table which was declared in a file A.mmx which is included both by a.mmx and by b.mmx, and such that the code in b.mmx will only work correctly after initialization of this table.
Whenever the above situation occurs, we may perform a virtual inclusion of a.mmx into b.mmx
|
Virtual inclusions do not create any dependencies for the build process, but they do influence the list of files which need to be compiled and linked, as well as the order in which the various files of the project are executed (see section ? below).
Whatever inclusion modes are used, no circular chain of inclusions is
allowed in
In the case when some code in a file b.mmx depends on some code in the file a.mmx and vice versa, the programmer will have to explicitly include prototypes for the required functionality in one of the files. Class prototypes are declared using the syntax
|
Function prototypes are declared using the syntax
|
Duplicate inclusions. Initialization only once, for the first inclusion.