最近发现了一个C++的头文件bits/stdc++.h,听说这是一个几乎包含了所有C++库函数的头文件,就想更深入的了解一下,下面是头文件内容
1 // C++ includes used for precompiling -*- C++ -*- 2 3 // Copyright (C) 2003-2013 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 //. 24 25 /** @file stdc++.h 26 * This is an implementation file for a precompiled header. 27 */ 28 29 // 17.4.1.2 Headers 30 31 // C 32 #ifndef _GLIBCXX_NO_ASSERT 33 #include34 #endif 35 #include 36 #include 37 #include 38 #include 39 #include 40 #include 41 #include 42 #include 43 #include 44 #include 45 #include 46 #include 47 #include 48 #include 49 #include 50 51 #if __cplusplus >= 201103L 52 #include 53 #include 54 #include 55 #include 56 #include 57 #include 58 #include 59 #include 60 #include 61 #endif 62 63 // C++ 64 #include 65 #include 66 #include 67 #include 68 #include 69 #include 70 #include 71 #include 72 #include 73 #include 74 #include 75 #include 76 #include 77 #include 78 #include 79 #include
80 #include
看了别人对于这个头文件的看法,自己也有了更深的认识,包含大量不需要的库的头文件,更适合在oj比赛中使用。如果在软件工程的开发中,我们应该减少包含,控制编译时间和代码大小。
优点如下:
1.在竞赛中节约时间
2.减少了编写所有必要头文件的工作量
3.对于使用的每个函数,不用记住GNU C++的所有STL
缺点如下:
1.不属于GNU C++库的标准头文件,在部分情况下可能会失败
2.使用它将包含许多不必要的东西,并增加编译时间
3.这个头文件不是C++标准的一部分,因此是不可移植的,应该避免
4.编译器每次编译翻译单元时都必须实际读取和分析每个包含的头文件,应该减少这类头文件的使用
参考地址:
https://blog.csdn.net/qq_20240999/article/details/59111606
https://www.geeksforgeeks.org/bitsstdc-h-c/