C++ Applications Use STRICT Type Checking
Go Up to C++ Specifics Index
The default type checking scheme for new C++ applications is STRICT, as if you had set #define STRICT
(this applies to 64-bit Windows as well as 32-bit Windows applications). Applications created prior to C++Builder 2007 still use the previous default, #define NO_STRICT
. The VCL now mangles Windows handle parameters to match the C++ STRICT mangling scheme, and compiling in STRICT mode has the advantages of providing enhanced type-safety and matching the native mangling of the VCL.
Contents
Migrating Your Code from NO_STRICT
It is recommended that you upgrade applications that define NO_STRICT, so that they will compile in STRICT mode (the first step is removing the NO_STRICT conditional define, as described in this topic). However, the VCL still provides entry-points for applications that define NO_STRICT, and if your code does not compile in STRICT mode, you can continue to use NO_STRICT. Be aware, though, that this might change in the future.
- For more information about STRICT type checking, see the MS Windows Platform SDK help, under Windows Development/Using the Windows Headers: http://msdn.microsoft.com/en-us/library/aa383732(v=vs.85).aspx
- For information about installing MS SDK Help on your system, see "Installing the Online Help" in the product Install.html file, located on EDN at http://edn.embarcadero.com/article/40774
How to Know Whether An Application Uses NO_STRICT
A quick way to find code projects that have NO_STRICT defined is to search for NO_STRICT in your *.cbproj
files.
- Note: C++Builder project files (
.cbproj
files) cannot be displayed or edited in the Code Editor, and should not be altered in a different editor, but you can search a.cbproj
file using another editor or a search utility. For example, you can use GREP.
For specific projects, you can use the IDE to remove the NO_STRICT define, as described in the following steps.
Removing the NO_STRICT Conditional Define
- Open a project that has NO_STRICT defined.
- Select Project > Options > C++ (Shared Options) (this is the very top page in the Project Options dialog box).
- In the Build Configurations field at the top of the page, select the configuration that you want to use the STRICT conditional define (such as the Base configuration). Note: If the Conditional defines field contains "Inherit Value from <configuration_name>", you need to select the named parent configuration (indicated in <configuration_name>) in the Build Configuration field.
- In the Conditional defines field, highlight NO_STRICT and delete it.
- Click OK on the Conditional defines dialog box.
- Click OK on the Project Options dialog box.
- Rebuild your project and correct any errors that appear as the result of type checking, especially in calls to Windows procedures.
Adding the STRICT Define (Optional)
Removing the NO_STRICT conditional define is equivalent to setting the STRICT conditional because STRICT is the default. However, you can optionally add the STRICT conditional define by following these steps:
- Select Project > Options > C++ (Shared Options) (this is the very top page in the Project Options dialog box).
- In the Build Configurations field at the top of the page, select the configuration that you want to use the STRICT conditional define (such as the Base configuration). Note: If the Conditional defines field contains "Inherit Value from <configuration_name>", you need to select the named parent configuration (indicated in <configuration_name>) in the Build Configuration field.
- On the Conditional defines field, click the ellipsis button
.
- On the Conditional Defines dialog box, enter STRICT in the text entry field, and click Add.
- Click OK on the Conditional defines dialog box.
- Click OK on the Project Options dialog box.
- Rebuild your project and correct any errors that appear as the result of type checking, especially in calls to Windows procedures.
Type Checking Problems Using Older Windows Types
Before Windows 3.1, Windows types, like HWND and HMENUS, were of type void *
. This meant that
a Windows procedure could be called with HWND or an HMENUS as a parameter, and Windows could not tell them
apart. With the introduction of Windows 3.1, many of these types were changed to distinct types. Now Windows
can determine if you are calling with the wrong type.
This change left a huge task for developers of legacy applications -- to change types of parameters used in these Windows procedure calls. The NO_STRICT conditional define alleviates this conversion. With NO_STRICT set, the VCL provides entry points to overloads of Windows procedures that accept the old parameter types and do the conversion.