Strict type checking strict type check

Source: Internet
Author: User
Strict type checking
The windows. h header file contains definitions, macros, and struct to help you write source code that can be transplanted in different versions of Windows. When you define the strict symbol when compiling an application, some of these functions will be activated. The following topics explain the benefits of the strict function and how to use them to affect code writing.
Using strict type check -----------------
When you define the strict symbol, you can enable the function that requires more caution when defining and using types (you enable features that require more care in declaring and using types ). This will help you write code that is easier to transplant. These additional considerations will also reduce your debugging time. Opening strict will redefine some data types, so the compiler will not allow assignments without explicit cast. This is especially useful for Windows code. Errors of passing data types will be reported during compilation, rather than causing serious errors during runtime.
When strict is defined, the following data type definition is changed:
The special handle type is defined as mutex. For example, you cannot pass an hwnd to a place where HDC type parameters are required. If there is no strict, all the handles are defined as integer, so the compiler cannot prevent you from using another type when you need one type of handle.
All callback function types (such as the dialog box process, Window Process, and hook process) are defined in a complete prototype. This prevents you from using incorrect parameter lists when defining callback functions.
Parameters and return types that require generic pointers are correctly declared as lpvoid rather than lpstr or other pointer types.
The COMSTAT struct is declared in accordance with ANSI standards.
Disabling strict disable strict type check --------------
In Visual C ++, strict type check is defined by default
To disable strict, define the symbol "no_strict ". in version 6.0, open the Project Settings dialog box, select the C/C ++ label, select general in category, and define Preprocessor Definition) type no_strict. you can also specify the definition on the command line or set/dno_strict in the group as the compilation option.
To define no_strict on a file-by-file basis (supported by C but not c ++, as explained in the note that follows), including windows. insert a statement before h # define statement.
# Define no_strict
# Include <windows. h>
To produce the best results, you also need to set the error message warning level to the minimum/w3. this is always feasible for Windows programs, this is because an incorrect programming practice that causes a warning usually leads to a serious running error. For example, an incorrect number is passed as a parameter.
Strict compliance complies with local rules ------
Some source code may cause compilation errors when strict type check is enabled. The following section describes the minimum conditions for your code to pass strict type checks. We recommend that you perform these additional steps, especially when you need to generate portable code.
General requirements
The main requirement is that you must declare the correct handle type and function pointer instead of relying on the common type. You cannot use another type where one type of handle is needed. This also means that you must change the function declaration and use more type conversions. To achieve the best results, the general handle type is used only when necessary.
Declare functions in your program
Make sure all application functions are declared. We recommend that you put all function declarations into an include file so that you can easily view the Declaration and find parameters and return values that need to be changed.
If you use the/ZG compilation option to generate a header file for your function, remember whether to enable strict will produce different results. If strict is disabled, all handle types are generated as the same base type.
Any function declaration that you copy from windows. h to your source code will be changed. However, your local declaration will be obsolete and your local declaration will be cleared.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.