Reading en.cppreference.com on fputc()/putc(), I stumbled upon the following statement:
In C, putc() may be implemented as a macro, which is disallowed in C++.
Is this true? If so, where (in the C++ standard) is this stated?
Possibly related: https://stackoverflow.com/questions/10712423
putc
is specified as a function in the C standard:
7.19.7.8 The putc function
The C standard permits any C standard library function to be implemented as a macro (a real function implementation still needs to be provided, but if a macro is defined in the header, that's what will be used):
7.1.4 Use of library functions
Any function declared in a header may be additionally implemented as a function-like macro
But the C++ standard specifically states that these must be defined as functions:
17.4.1.2.6 Headers
Names that are defined as functions in C shall be defined as functions in the C++ Standard Library.
The footnote explicitly clarifies that an additional macro definition is not allowed:
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 inlin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With