Carl said:
Not to defned header files too much (they're a blight, but necessary for
now), keep in mind that most of those other languages expose only a tiny
fraction of what's made available through <windows.h> - far less than 10% in
most cases if I had to guess (and that's exactly what it is).
I´ve not yet missed anything of windows.h in other languages. Normally
you need only the import definitions for the windows dll´s. And some
libraries do that declarations of their own, e.g. boost.
But may be we should compare the windows.h header with a .NET language
like C#. All functions of the windows.h header are available through the
..NET framework, though they have not the same name or parameters.
Win32->.NET:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/win32map.asp
Additionally the framework has much more functions and classes than the
windows.h header.
But if you compare the compilation speed of a C# project to a C++
project including the windows.h header, the C# compiler is still much
faster than the C++ compiler. And even the C++ compiler is much faster
in compilation when you use only functions of the .NET framework than
functions of the Win32 API.
That notwithstanding, it's certainly the case that a pre-parsed interface
definition file is likely to be much faster to import than a multi-megabyte
string of C/C++ declarations.
Note also that a precompiled header can be thought of as just such a
pre-parsed interface file - it just so happens that the end user needs to
create the file instead of the language system coming with one prebuilt.
Once you've built the PCH file for your app, what difference does it make,
practically speaking?
I don´t know the internals of e.g. Delphi (Pascal), but AFAIK it
generates some kind of preparsed intermediate code or interface
definition embedded in it´s generated "object" files, so if you
"include" the source file in another location the compiler doesn´t have
to recompile it, since it already has done that. This is only "second
hand" information, so it might be not quite correct.
I use Delphi occasionally for GUI applications, since i mostly do
console / service applications i prefer normally C++ for that task. But
the compilation speed is impressive, though the language isn´t that
complex than C++.
If you include a large number of header files, directly or indirectly in
a cpp file the compiler has to recompile all the header files, although
it already has done that before - except if you are using precompiled
header files and include them in correct order if you are using more
than one.
But it don´t see a reason (except macros), why the C++ compiler
shouldn´t be able to automatically create a precompiled header file for
each header file it has compiled ?! If for such an automatism a
restriction of macros is needed, i´m willing to restrict myself.
I think disc spaces isn´t a problem anymore.
Of course, if you put inappropriate things (i.e. things that change often)
into your PCH file, you won't really enjoy the benefits.
If the compiler would create multiple precompiled header files
automatically even that problem would be solved ;-)
Andre