Using STRICT to Improve Type Checking

OverviewHow Do I

When you define the STRICT symbol, you enable features that require more care in declaring and using types. This helps you write more portable code. This extra care will also reduce your debugging time. Enabling STRICT redefines certain data types so that the compiler won’t permit assignment from one type to another without an explicit cast. This is especially helpful with Windows code. Errors in passing data types are reported at compile time instead of causing fatal errors at run time.

When STRICT is defined, WINDOWS.H type definitions change as follows:

  • Specific handle types are defined to be mutually exclusive; for example, you won’t be able to pass an HWND where an HDC type argument is required. Without STRICT, all handles are defined as integers, so the compiler doesn’t prevent you from using one type of handle where another type is expected.

  • All callback function types (dialog procedures, window procedures, and hook procedures) are defined with full prototypes. This prevents you from declaring callback functions with incorrect parameter lists.

  • Parameter and return value types that should use a generic pointer are declared correctly as LPVOID instead of as LPSTR or another pointer type.

  • The COMSTAT structure is declared according to the ANSI standard.

What do you want to know more about?