Home > Backend Development > C++ > Why does `printf` work in both `std::printf` and `printf` when using `` in C ?

Why does `printf` work in both `std::printf` and `printf` when using `` in C ?

Barbara Streisand
Release: 2024-10-26 05:43:30
Original
631 people have browsed it

Why does `printf` work in both `std::printf` and `printf` when using `` in C  ?

cstdio Stdio.h Namespace

In the C reference documentation for , it claims that all library elements reside within the std namespace. However, experiments show that both std::printf and printf function calls work. Does this indicate that C headers import symbol names into both the std and global namespaces?

Answer

Including imports symbol names into the std namespace, and potentially the global namespace. In contrast, including imports symbol names into the global namespace, potentially incorporating them into the std namespace as well.

This behavior extends to all C-style headers. According to the C 11 standard (Annex D), C standard library headers behave as follows:

"2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope."

Therefore, it remains uncertain whether these names are initially declared or defined within the namespace std and then injected into the global namespace via using-declarations, or vice versa.

The above is the detailed content of Why does `printf` work in both `std::printf` and `printf` when using `` in C ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template