You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: c/cpp.cpp
+22-17Lines changed: 22 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -44,27 +44,32 @@ for the rest, go to c.c
44
44
45
45
#headers
46
46
47
-
stdlib headers don't have the .h extension
47
+
stdlib headers that are not c stdlib headers don't have the .h extension
48
48
49
-
when writting new libs, you use the extension ``.h`` or ``.hpp``
49
+
with `g++` those get linked to automatically
50
50
51
-
with ``g++`` those get linked to automatically
51
+
when writting new libs, you can use either `.h` or `.hpp` as extensions.
52
52
53
53
the main c++ lib on linux is the GNU Standard C++ Library vX
54
54
55
-
- std bin is located at: ``/usr/lib/i386-linux-gnu/libstdc++.so.X``. Try ``locate libstdc++``.
56
-
- std headers are located at: ``/usr/include/c++/4.X/``. Try ``locate /iostream``.
55
+
- std bin is located at: `/usr/lib/i386-linux-gnu/libstdc++.so.X`. Try `locate libstdc++`.
56
+
- std headers are located at: `/usr/include/c++/4.X/`. Try `locate /iostream`.
57
57
58
-
Note: c++ std headers have no ``.h`` extension, just like when included.
58
+
Note: c++ std headers have no `.h` extension, just like when included.
59
59
60
-
- the ubuntu package is called ``libstdc++6.X``. ``dpkg -l | grep libstd``
60
+
- the ubuntu package is called `libstdc++6.X`. `dpkg -l | grep libstd`
61
61
62
62
#c stdlin can be accessed
63
63
64
-
math vs cmath, X vs cX
64
+
c++ is a backwards compatible extension of c, therefore it must provide all the c headers with the exact same semantincs.
65
65
66
-
cX puts things in std:: namespace. *always* use it.
67
-
X.h puts *all* in the global namespace. *never* use it.
66
+
However, it also provides a cNAME version to every NAME.h, ex: `math.h` vs `cmath`.
67
+
68
+
The difference is the following:
69
+
70
+
- cX puts things in std:: namespace. *always* use it on new code, since this reduces the probability of a name conflicts, and is the standard c++ way of doing things.
71
+
72
+
- X.h puts *all* in the global namespace, it is exactly the same as the c headers. *never* use it in the code.
0 commit comments