| Quentin (47) | |||
|
Hi there, I'd like to know why is the following code correct according to g++:
We call strlen functions without and preceded by the std:: prefix. Both of them produce the same output - "3". Is it somehow conformant to the C++ Standard? In my opinion the line with: strlen("Foo")should result in an error beacuse of the lack of the using directive. Regards. | |||
|
Last edited on
|
|||
| Framework (3237) | |||
|
No, it doesn't. Initially, <cstring> includes <string.h> which defines "strlen( )" globally. The <cstring> header pulls that definition into the "std" name-space but the original definition of "strlen" is still globally defined for backwards compatibility for programs with a C base. Compile this and see for yourself:
Wazzak | |||
|
Last edited on
|
|||
| Cubbi (1927) | |
| the standard specifically allows implementations to include strlen( ) along with std::strlen() when <cstring> is included (same for all C library declarations) . Some compilers don't do it (Sun Studio for example), others do (GCC for example). Both are right, but a standard-compliant program won't attempt to use strlen | |
|
Last edited on
|
|