I hate the “c…” headers
By chys on June 19th, 2009What’s the reason for using <cstdio> instead of <stdio.h>? Merely to pretend more standard compliant?
Framers of the C++ standard probably wished to “clean” the global namespace by pulling everything into std. Unfortunately, many implementations (Microsoft, GNU, etc.) instead put all those symbols in both the global and std namespaces, rendering this argument invalid in practice.
Even more unfortunately, a few other well-known implementations (e.g. Solaris) actually followed the standards.
Actually I lost some points in a course for exactly this reason, in which the TA failed to compile on Solaris my program which compiled well on Linux. In that program I included <cstdio> but forgot to pretend std:: to two printf’s. Since then, I have always been using <name.h> rather than <cname> though “deprecated.”
To write strictly conforming programs, we need to remember what symbols are macros and what are not. The C++ standard lists those symbols which are symbols:
[Note: the names defined as macros in C include the following:
assert,errno,offsetof,setjmp,va_arg,va_end, andva_start. -end note]
They had the rarely-used setjmp here, but omitted three very important ones which the C standard says should be macros. Let’s look into the header stdio.h provided by glibc:
/* Standard streams. */
extern struct _IO_FILE *stdin; /* Standard input stream. */
extern struct _IO_FILE *stdout; /* Standard output stream. */
extern struct _IO_FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr
They’re not in std either.
Related posts:
Tags: C/C++
