April 26, 2024, 08:25:18 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Undocumented feature: precompiled headers

Started by sapero, March 15, 2011, 03:24:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

March 15, 2011, 03:24:41 AM Last Edit: March 15, 2011, 01:30:42 PM by sapero
The 2.0 compiler includes a beta support for precompiled headers.

Precompiled code is useful during the development cycle to reduce compilation time, especially if:
  • You always use a large body of code that changes infrequently.
  • Your program comprises multiple modules, all of which use a standard set of include files and the same compilation options. In this case, all include files can be precompiled into one precompiled header.

The usage is very simple: create an include file called stdafx.inc, and place in it all the code, definitions, or include other headers you want to precompile, then include stdafx.inc file in your source file(s).
The compiler, while parsing the stdafx.inc header will create stdafx.pch binary file with the precompiled contents of the header. If the PCH file already exists, the compiler will compare last-modified time of all referenced files (stdafx.inc file and all files included from it). If you modify any referenced file, the PCH file will be recreated.

Example: create a project with two or more source files. Place the following line in all source files:
$include "windowssdk.inc"
It can be any other .inc file, but it should be really huge.
Save the project and compile. Notice how much time is required to compile the project (~1.5s * number of source files).

Now replace windowssdk with stdafx in all source files, create stdafx.inc file in project directory, open it in the editor and place the above line in it ($include windowssdk). Compile again and notice the boost.
For the first time (when the PCH file does not exists) or the PCH file is rebuild, it will take a bit longer to compile the project, because the compiler will access windowssdk.inc and all the referenced headers. For the second time, the project will be compiled in a second.

The name of include file "stdafx.inc" is reserved for precompiled headers. The current parser version (2.0) does not correctly handle SELECT, CASE, CASE&, DEFAULT keywords while creating/reading precompiled headers.

The precompiled header can be used without creating a project. The same INC+PCH file may be used for all projects or single-file programs, just place the INC and PCH file in some shared location.
Attached is a sample project with 4 source files - the content of windowssdk.inc is available in all source files.

See also disphelper integration

LarryMc

Sapero
I converted my visual designer over to use this scheme.
Ran into a problem

I added a dialog to one of my 52 source files.
I defined the dialog variable in my globals.iwb file.

(there was already an existing pch file.)
(the stdafx.inc file contains $include "globals.inc")

when I recompiled the entire project it failed.
the file that contain the create statement for the dialog said the dialog variable was not defined.

I looked at the pch file and it had not been updated; it was still the old version.
I deleted the pch file and recompiled the project and everything worked fine.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library