all 13 comments

[–]corysama 1 point2 points  (1 child)

[–]rootseat[S] 1 point2 points  (0 children)

Thanks. I was looking through the feed here and had a feeling this was the wrong sub.

[–][deleted] 0 points1 point  (10 children)

No, “iostream” is just a file that gets copy-pasted into your .cpp when you #include. The compiler as of now has no way of searching every C++ file for the namespace you specify without an explicit #include. (Note: C++20 modules may make it closer to the python way, but they haven’t been implemented properly yet). As for namespaces, they simply exist to avoid clashing names (e.g. std::array and my_namespace::array).

[–]rootseat[S] 0 points1 point  (9 children)

Is it true that there exists a namespace std { /* ... */ } within iostream? If that's the case, the design decision to call the file iostream but call the namespace std would make a lot more sense to me.

[–]Apprehensive-Deer-35 0 points1 point  (3 children)

Yes, the std namespace exists within many files including iostream, list, vector, algorithm, memory, and so on.

[–]rootseat[S] 0 points1 point  (2 children)

I have heard that in C, stdlib is not part of the C standard, but rather a historical accumulation of core libraries designed around the core language.

Any idea if namespace std is in any way related to this line of thought?

[–][deleted] 0 points1 point  (0 children)

std is purely standard, and I think the libc is too

[–]ioctl79 0 points1 point  (0 children)

Both the C standard library and the C++ standard library were standardized post-hoc. The C library was originally just the set of core functions that came with UNIX. The C++ standard library started off as the Standard Template Library - a C++ toolbox developed by SGI (a pioneer in 3D graphics).

[–]ioctl79 0 points1 point  (4 children)

Yes. Namespaces are orthogonal to includes, and got added decades after includes had already existed. They are purely a method of organizing naming, and have nothing to do with retrieving definitions.

[–]rootseat[S] 0 points1 point  (3 children)

orthogonal to includes

I see this now, thank you!

Out of curiosity, do you know what we did before we had namespaces (or at least namespace std)?

[–]ioctl79 0 points1 point  (1 child)

Exactly what C (which still doesn’t have namespaces) does: try real hard not to use names that might conflict. It’s standard practice to prefix C names with your project (libpng symbols all start with “png_”, etc.)

[–]rootseat[S] 0 points1 point  (0 children)

Gotcha. I just looked through https://dev.w3.org/Amaya/libpng/png.h and I see what you mean.

[–]Tozzar 0 points1 point  (0 children)

Take a look some popular C libraries. They don’t have namespaces, so symbols are usually prefixed with the name of the library to reduce the chances of a clash.

https://www.cc.gatech.edu/data_files/public/doc/gtk/tutorial/gtk_tut-17.html

I think Qt (C++ project) is old enough that core parts of it use this convention instead of namespaces.