Visual Studio 标准库中的额外内容
Extra includes in visual studio's standard library
我注意到,当您在Visual Studio的标准库中包含其中一个标头(如iostream
、vector
、set
等)时,它还包含其他一些标头。
#include <set>
int main()
{
int A[1000];
std::max(3,5);
memset(A,0,sizeof(A));
pow(2,2);
printf("hi");
}
以上代码在Visual Studio中编译时没有任何错误,但在gcc中会导致编译错误
我假设VisualStudio默认包含一些库。但在网上搜索后,我发现这不是真的。所以我意识到这是因为标准库在不同编译器中的实现方式不同。所以我想知道这个额外的包含背后的原因是什么?我不认为set
使用pow
或printf
。
这很容易发生。
<set>
将引入<set>
在其声明中使用的任何内容。例如,它将为std::allocator_traits
引入<memory>
。
反过来,<set>
拉入的所有内容都会拉入其他内容。等等……如果其中一个标头包含<cmath>
,那么你就会突然得到std::pow
。
当这些标头需要其他标头才能工作时,就会发生这种情况。
它完全依赖于实现。正如您需要在自己的代码中包含头一样,创建这些头的人也需要在他们的代码中包含其他头才能使其工作。
不要依赖它。总是包括你需要的东西。
对gcc使用-H参数表明,包含set
会导致包含:
. include/c++/set
.. include/c++/bits/stl_tree.h
... include/c++/bits/stl_algobase.h
.... include/c++/i686-w64-mingw32/bits/c++config.h
..... include/c++/i686-w64-mingw32/bits/os_defines.h
..... include/c++/i686-w64-mingw32/bits/cpu_defines.h
.... include/c++/bits/functexcept.h
..... include/c++/bits/exception_defines.h
.... include/c++/bits/cpp_type_traits.h
.... include/c++/ext/type_traits.h
.... include/c++/ext/numeric_traits.h
.... include/c++/bits/stl_pair.h
..... include/c++/bits/move.h
...... include/c++/bits/concept_check.h
.... include/c++/bits/stl_iterator_base_types.h
.... include/c++/bits/stl_iterator_base_funcs.h
..... include/c++/debug/debug.h
.... include/c++/bits/stl_iterator.h
... include/c++/bits/allocator.h
.... include/c++/i686-w64-mingw32/bits/c++allocator.h
..... include/c++/ext/new_allocator.h
...... include/c++/new
....... include/c++/exception
........ include/c++/bits/atomic_lockfree_defines.h
.... include/c++/bits/memoryfwd.h
... include/c++/bits/stl_function.h
.... include/c++/backward/binders.h
.. include/c++/bits/stl_set.h
.. include/c++/bits/stl_multiset.h
.. include/c++/bits/range_access.h
使用/showIncludes for Visual Studio显示包含set
会导致包含:
VCINCLUDEset
VCINCLUDExtree
VCINCLUDExmemory
VCINCLUDExmemory0
VCINCLUDEcstdlib
VCINCLUDEyvals.h
VCINCLUDExkeycheck.h
VCINCLUDEcrtdefs.h
VCINCLUDEsal.h
VCINCLUDEConcurrencySal.h
VCINCLUDEvadefs.h
VCINCLUDEuse_ansi.h
VCINCLUDEstdlib.h
VCINCLUDEcrtdefs.h
VCINCLUDElimits.h
VCINCLUDEcrtdefs.h
VCINCLUDElimits
VCINCLUDEymath.h
VCINCLUDEcfloat
VCINCLUDEfloat.h
VCINCLUDEcrtdefs.h
VCINCLUDEcrtwrn.h
VCINCLUDEcrtdefs.h
VCINCLUDEclimits
VCINCLUDEcmath
VCINCLUDEmath.h
VCINCLUDEcrtdefs.h
VCINCLUDExtgmath.h
VCINCLUDExtr1common
VCINCLUDEcwchar
VCINCLUDEwchar.h
VCINCLUDEcrtdefs.h
VCINCLUDEswprintf.inl
VCINCLUDEwtime.inl
VCINCLUDExstddef
VCINCLUDEcstddef
VCINCLUDEstddef.h
VCINCLUDEcrtdefs.h
VCINCLUDEnew
VCINCLUDEexception
VCINCLUDEeh.h
VCINCLUDEcrtdefs.h
VCINCLUDEmalloc.h
VCINCLUDEcrtdefs.h
VCINCLUDEstring.h
VCINCLUDEcrtdefs.h
VCINCLUDExutility
VCINCLUDEutility
VCINCLUDEiosfwd
VCINCLUDEcstdio
VCINCLUDEstdio.h
VCINCLUDEcrtdefs.h
VCINCLUDEcstring
VCINCLUDEcrtdbg.h
VCINCLUDEcrtdefs.h
VCINCLUDEtype_traits
VCINCLUDExrefwrap
VCINCLUDExatomic0.h
VCINCLUDEintrin.h
VCINCLUDEcrtdefs.h
VCINCLUDEsetjmp.h
VCINCLUDEcrtdefs.h
VCINCLUDEimmintrin.h
VCINCLUDEwmmintrin.h
VCINCLUDEnmmintrin.h
VCINCLUDEsmmintrin.h
VCINCLUDEtmmintrin.h
VCINCLUDEpmmintrin.h
VCINCLUDEemmintrin.h
VCINCLUDExmmintrin.h
VCINCLUDEmmintrin.h
VCINCLUDEcrtdefs.h
VCINCLUDEammintrin.h
VCINCLUDEmm3dnow.h
VCINCLUDEcrtdefs.h
VCINCLUDEmmintrin.h
VCINCLUDEstdexcept
VCINCLUDExstring
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 你能重载对象变量名本身返回的内容吗
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 将一个宏传递到另一个宏而不是直接传递内容时会出现不需要的额外"空"参数
- 在 Visual Studio 中调试时,是否可以将一些 C/C++ 结构内容保存到磁盘?
- 任何人都可以在带有JNI的Android Studio上帮助我解决此错误,是否缺少一些内容?
- Visual Studio 2017 C++:克隆的 git 存储库中缺少包含的内容
- boost::log 输出到 Visual Studio 输出控制台 - 为格式添加额外的 LF/CR
- 查看提升::可选内容,同时在 Android Studio 中进行本机调试
- 在Visual Studio调试器中查看C 智能指针数组的内容
- Visual studio:在生成过程中复制内容,而不考虑 cpp 更改
- 防止Visual Studio C++控制台立即退出,而无需系统("pause")或额外的获取
- LNK2019尽管有代码的内容(Visual Studio 2013,C++)
- 为什么以下内容无法在Visual Studio 2010 C++下编译
- 在Visual Studio中加载文本文件资源加载的内容超过了应有的水平
- 如何在Visual studio 2010中查看存储在std::deque中的内容(调试模式)
- Visual Studio 标准库中的额外内容
- Visual Studio 2012 c++构建失败,但错误列表或输出中没有任何内容
- Visual Studio 2010 找不到除解决方案的局部变量之外的任何内容的定义