Stl source code analysis: Compiler's predefined location set settings, stl source code
At present, my work environment is win, and all demonstrations also use VS or cygwin as the basis.
1. Add the include object to the configuration item and add the pre-defined position set settings. The compiler will add it to the include path, for example, defining a vector (without a suffix) in a folder ), when # include <> is used in our project, two vectors can be searched, respectively, in the Custom and built-in C ++ stl. However, during actual project compilation, you will find that the files in the Custom pre-defined location set have a high priority, simply put, the stl standard library will be replaced by the custom library in the case of path ambiguity.
Conjecture 1: if there are two identical files in different paths added to the predefined location set, include adopts the ambiguous form, that is, the complete path is not included, which file is used?
Test result: VS compilation uses Path 1. Other compilers still need to perform the test again, for example, gcc 4.8.3. To be continued ..
Conjecture 2: if there are two identical files in different paths added to the predefined location set, the include method is non-ambiguous, that is, the complete path # include <test/vector>. Can two files be used at the same time? Or which file is used?
Test result: VS compilation uses Path 1. Other compilers still need to perform the test again, for example, gcc 4.8.3. To be continued ..
Compilation result:
1> ------ generated: Project: TestSizeofBits, configuration: Debug Win32 ------ 1> stdafx. cpp1> TestSizeofBits. cpp1> d: \ cpp_lab \ testsizeofbits \ include4 \ OK \ vector (4): error C2084: function "void print (void)" already has a Subject 1> d: \ cpp_lab \ testsizeofbits \ capacity DE3 \ include \ vector (3): see the previous definition of "print" 1> d: \ cpp_lab \ testsizeofbits. cpp (151): error C3861: "print": unable to find the identifier 1> testNamespace. cpp1> generating code... ============ generate: 0 successful, 1 failed, 0 latest, skipped 0 ==========
That is to say, the VS compiler identifies non-Ambiguous files and conflicts with names. After I use the namespace to process conflicts between two files, VS can correctly identify the content of the two files and complete the link.
Why should I test this? Because I want to introduce the content of library sgi_stl or boost into my file, but there will be conflicts with the same name. As long as the path and namespace are processed, the User-Defined library with the same name can be used correctly.
// Vector
#pragma once#include <iostream>void print3(){std::cout<<"jingz;s vector3"<<std::endl;}
#include <include/vector>#include <ok/vector>#include <vector>
print3();print4();vector<int> arrInt(10);arrInt[0] = 1;cout<<arrInt[0]<<endl;
The test program runs correctly.
Conjecture 3: Is the predefined command affected?
Result: I tried different predefined values, but they didn't change.
Conclusion: You can replace the corresponding database by adding a custom location set. When designing a library, it is compatible with programmers who need to use custom components to replace the components provided by the default library.
Comments, good or bad. Please support genuine links.