Ian Collins wrote:
>
Pietro Cerutti wrote:
Hi Group,
is there a mean to undefine a function, in a similar way as you can
undefine macros?
For example, let's say that I need a few declarations from stdio.h but
want to define my own printf:
[...]
No, once a symbol is declared in a compilation unit, it's definition can
not be changed.
The best you can do is something gross like:
#define puts _puts
#include <stdio.h>
#undef puts
void puts( int n ) {}
int main(void) {
puts( 42 );
}
Or:
#include <stdio.h>
#undef puts
#define puts MyPuts
...
Besides, doesn't the standard forbid you from replacing standard
library functions? For example, I have seen compilers which can
inline some standard functions, like strcpy(), so even if you
had a function called strcpy(), it wouldn't be called.
BTW, is it legal to #undef something that hasn't been #define'd?
Does the above need a #ifdef around the #undef? (My compiler
doesn't complain about it.)
Hold on... I knew I downloaded n1124.pdf for a reason...
Don't mind me. Just go about your things while I have this
conversation with myself.
6.10.3.5p2
(#undef)
It is ignored if the specified identifier is not currently
defined as a macro name.
So, to answer my own question... Yes, it is perfectly legal to
#undef something which isn't #define'd already.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>