Using C Headers in C : Namespace Considerations
In C , the use of C headers raises a question regarding namespace usage. While C functions and headers can be employed in C after minor modifications, the syntax remains ambiguous with both printf("Hello world!") and std::printf("Hello world!") producing the same output.
Namespace Behavior in C 11
According to the C 11 Standard, C headers like name.h introduce names both in the global namespace and the std namespace. However, the declaration order within each namespace is unspecified.
For example, the header
Recommended Practice
Given that using
Example
Prefer the following code:
#include <cstdio> int main() { std::printf("Hello world\n"); }
Avoid this code:
#include <stdio.h> int main() { printf("Hello world\n"); }
By adhering to these practices, C code ensures consistency, clarity, and compliance with the latest C Standards.
The above is the detailed content of Why Use `` Over `` in C ?. For more information, please follow other related articles on the PHP Chinese website!