Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Visual Stuio 2005 compiler

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use the Visual Stuio 2005 compiler", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use the Visual Stuio 2005 compiler" this article.

The Visual Stuio 2005 compiler now ensures that all local global variables and objects are initialized before initializing managed global variables and objects. This means that previous code may encounter an unprecedented compiler error in terms of properties. no, no, no.

1. Validity of parameters

In the C runtime library, some code has been added to check the validity of the parameters. For example, if the target buffer passed is not large enough for strcpy to use-- this is usually a security risk, while the new version invokes an illegal parameter handler. In the release version, Dr.Watson; is called, while in the debug version, assert is generated. Of course, as long as the parameters passed in the program are valid, there will be no problem.

2. Warning to non-secure API

In Visual C++ 2005, a set of functions in CRT is no longer recommended and should use the newly provided secure version. Most of these deprecated functions, if used improperly, will cause buffer overflows or other security issues, such as strcpy, strcat, and so on. The new secure versions of these functions all have a _ s suffix after the function name for easy identification, such as strcpy_s, wcscpy_s, mbscpy_s, calloc_s, and strcat_s.

If you want to continue to use the old, unsafe function, add # define value of _ CRT_SECURE_NO_DEPRECATE at the beginning of the source code (where value represents a numerical value); however, it is recommended that you upgrade your code to use the new security function.

3. The iterator is out of bounds

The checked iterator (checked iterators) and debug iterator (debug iterators) are also updated for security reasons, and if the iterator is out of bounds, an illegal parameter handler is called accordingly.

Again, illegal parameter problems can be avoided by throwing an out-of-bounds exception. Add # define value of _ SECURE_SCL_THROWS to the code and set the value to 1 so that instead of calling the illegal parameter handler, an exception is generated.

You can also turn off this iterator check by setting the # defined value of _ SECURE_ SCL value to zero, which is usually turned on by default.

4. Time_t type

The time_t type is typically used to display the number of seconds since 1970. Until Visual C++ 7.1 (i.e. Visual C++ .net 2003), the time_t type was defined as a long, while in Visual C++ 2005, it was defined as a 64-bit type that could be used for display until 3000 years.

5. Link to CRT

Managed applications cannot now be statically linked to CRT. In the past, in Visual C++ 7.0 and 7.1 (referring to Visual Studio .NET 2002 and 2003), it was possible to generate CLR programs that statically linked to CRT, but it did not work in Visual Studio 2005.

6. Single-thread CRT support

In Visual Studio 2005, single-threaded CRT support has been removed. And from the perspective of development, most people are willing to use thread-safe multithreaded code in the future.

In threads, the _ nolock suffix can be used to optimize the code, but at the same time, these functions are not thread-safe.

7. Exception handling

There are two types of exception handling to choose from: / EHa (asynchronous) and / EHs (synchronous C++ exception). In the past, if / EHs was used, then in a catch (...) Block, it may or may not be possible to catch structured exceptions because this behavior is undefined and unreliable; now, when you use / EHs again, you can guarantee that structured exceptions will not be caught. If you want to be consistent with previous versions of Visual C++ and catch asynchronous structured exceptions, you should still use / EHa at compile time.

8. Initialization sequence

In the past, if there were both managed and local global variables and objects in the code, the initialization order was uncertain; if there was a managed object interoperable with the local object in the code, there was no guarantee which object was initialized first. The Visual Stuio 2005 compiler now ensures that all local global variables and objects are initialized before initializing managed global variables and objects.

9 、 printf

For now, the% n format indicator in printf is typically used to specify the number of characters output. This has been identified as a security hazard and disabled, but it can be enabled using set_printf_count_output; it can be disabled by passing a zero value (0) to set_printf_count_output, and any other value can be enabled again.

10. Swprintf function

In order to comply with the C++ standard, the swprintf function has also been modified, and now it has followed the C++ standard. In C++, overloading can be achieved with appropriate parameters; the old version of this function is no longer recommended because overloading is not allowed in C, so an error will be returned if you use the old format.

Breakthrough changes in compilers

In addition to those changes that affect the library, there are also some changes that affect the compiler. The following are the major compiler changes in Visual C++ 2005. Again, not all of the changes are listed here, but they are key changes identified by Microsoft VC++ users and internal partners.

A pointer to a member

In previous versions of the Visual Stuio 2005 compiler, a pointer to a member could be obtained without using the addressing operator (&). Now, Visual C++ 2005 has strictly followed the standard that the addressing operator must be used, which also helps to eliminate potential run-time errors. But it also results in many areas of the MFC library that need to be modified, which means that existing programs may be affected.

Scope restriction rule

In the for loop declaration, the scope restriction rule is not enforced by default. In previous versions, the lifetime of variables in the for loop would extend outside the loop, and for standards compatibility, variables defined in the for loop are now limited to the for loop.

Wchar_t Typ

Wchar_t is now the default built-in type. That is to say, perhaps in the past, wchar_t might have been treated as a unsigned short because it is not yet a built-in type, so it is likely to cause problems when compared with files that have variables of type wchar_t. In Visual C++ 2005, wchar_t is already a built-in type, that is, you need to make sure that previous use of wchar_t does not lead to translation to a unsigned short.

Exception handling

To keep up with the changes in the library, the compiler has made some changes so that structured exceptions are not caught. So, to be compatible with previous code, you should still use / EHa.

Parameter attribute

To provide more robust properties-- and for the robustness of the code-- the compiler will now check the properties of types, enumerations, and so on. This means that previous code may encounter an unprecedented compiler error in terms of properties.

Default is int

In order to follow the C++ standard, variables or functions that have no type declaration are no longer defaulted to the int type. However, it still works in C language, but not in C++ language. This even affects Microsoft's own code, including NT code, so the * way is still explicitly declared.

About the managed code of C

It is generally impossible for C language compilers to create managed code for CLR because the C language is not object-oriented and it does not conform to the model used by CLR, so any code compiled in C will conflict with CLR compiler settings. For example, if the / TC setting is used at compile time, and CLR is set, it will cause a conflict.

New Grammar for CLR

By setting the / clr compilation option, the C++ compiler accepts only the new syntax. This will force the promotion of the new syntax added to Visual C++ 2005 and discard the old code at the same time.

Security Check

Today, when security is getting more and more attention, the security check option / GS, which is turned on by default, still makes some sense. In the Visual C++ Visual Stuio 2005 compiler, the / GS option is used by default.

These are all the contents of the article "how to use the Visual Stuio 2005 Compiler". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report