Build a C ++ Development Environment Analysis

Source: Internet
Author: User

The C ++ development environment includes many new and improved functions for improving work efficiency. IDE has also been re-designed to provide developers with direct access to. NET Framework components. I think the C ++ development environment will make our work easier and easier.

1. let's take a look at the benefits of inline functions: from a user's perspective, inline functions look like common functions. They can have parameters, return values, and scopes, however, it does not introduce the burden of General function calls. In addition, it is safer and easier to debug than macros.

Of course, we should be aware that inline specifier is only a suggestion for the compiler, And the compiler has the right to ignore this suggestion. How does the compiler determine whether the function is inline or not? Generally, key factors include the size of the function body, whether a local object is declared, and the complexity of the function.

2. What will happen if a function is declared as inline but not inline? Theoretically, when the compiler refuses to inline a function, the function will be treated like a common function, but there will be some other problems. For example, the following code:

 
 
  1. // filename Time.h   
  2. #include<ctime>   
  3. #include<iostream>   
  4. using namespace std;   
  5. class Time   
  6. {   
  7. public:   
  8. inline void Show() { for (int i = 0; i<10; i++) cout<<time(0)<<endl;}   
  9. };  

Because the member function Time: Show () includes a local variable and a for loop, the compiler generally rejects inline and treats it as a common member function. However, the header file containing the class declaration will be separately # include into each independent compilation unit:

 
 
  1. // filename Time.h   
  2. #include<ctime>   
  3. #include<iostream>   
  4. using namespace std;   
  5. class Time   
  6. {   
  7. public:   
  8. inline void Show() { for (int i = 0; i<10; i++) cout<<time(0)<<endl;}   
  9. };  


When the program is linked, the linker will face two copies of the same Time: Show (), so the function re-defines the connection error. However, some old C ++ implementations can deal with this situation by treating an un-inlined function as static.

Therefore, each copy of the function is only visible in the compilation unit, so that the Link error is solved, but multiple copies of the function will be left in the program. In this case, the program performance is not improved, but the compilation and link time and the size of the final executable body are increased.
Fortunately, the un-inlined function in the new C ++ standard has changed.

A c ++ implementation must generate only one copy of the function. However, it may take a long time for all compilers to support this.
There are two more headaches about inline functions.

The first question is how to perform maintenance. A function may appear in an internal form at the beginning, but as the system expands, the function body may require additional functions, and the result inline function becomes unlikely, therefore, you need to remove the inline specifier and put the function body in a separate source file.

Another problem is that inline functions are generated when they are applied to the code library. When the inline function changes, the user must recompile their code to reflect this change. However, for a non-inline function, you only need to relink it.

What I want to talk about here is that inline functions are not a panacea for improving performance. Only when the function is very short can it get the desired effect. However, if the function is not very short and called in many places, it will increase the size of the executable body.

  1. How to Write C ++ project development and project plan correctly
  2. Summary Notes on learning and exploring C ++ library functions
  3. In-depth demonstration of high security of C ++
  4. Describes in detail how to accurately Write C ++ languages.
  5. In-depth demonstration of high security of C ++

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.