printf() as a macro in glibc 2.2.1?
Craig Rodrigues
rodrigc@mediaone.net
Mon Jan 22 19:41:00 GMT 2001
On Thu, Jan 18, 2001 at 05:52:46PM -0800, Ulrich Drepper wrote:
> Craig Rodrigues <rodrigc@mediaone.net> writes:
>
> > This particular piece of code is breaking my compilation of the ACE
> > C++ library ( http://www.cs.wustl.edu/~schmidt/ACE.html ), which has
> > an OS encapsulation layer for standard C functions.
>
> This means that the code is wrong. Each and every function in the libc
> can also be a macro.
I'm not sure if this is correct in the case of printf().
This could have ramifications on C++ code.
In Section 27.8.2 of the C++ Standard, fprintf(), printf(), and
vprintf() are defined as functions in the <cstdio> header.
Annex D (normative), in D.5 states that:
"Each C header, whose name has the form name.h, behaves as if each
name placed in the Standard library namespace by the corresponding
cname header is also placed within the namespace scope of the
namespace std and is followed by an explicit using-declaration".
So, using stdio.h in a C++ program should behave like:
#include <cstdio>
using std::fprintf;
using std::printf;
// more declarations here
In addition to that section 17.4.12(6) explicitly states:
"Names that are defined as functions in C shall be defined as functions
in the C++ Standard Library[159]."
and the footnote number [159] states:
[159] This disallows the practice, allowed in C, of providing a
"masking macro" in addition to the function prototype. The only
way to achieve equivalent "inline" behavior in C++ is to provide
a definition as an extern inline function.
--
Craig Rodrigues
http://www.gis.net/~craigr
rodrigc@mediaone.net
More information about the Libc-alpha
mailing list