c++ - why cstdio undef gets or other functions -
when read libstdc++-v3/include/c/cstdio,i'm quite confused lines below:
//get rid of macros defined in <stdio.h> in lieu of real functions. #undef getc #undef gets
i think getc
macro gets
function in fact, why undef function? may in system it's implemented in macro?
update: try put understanding <stdio.h>
, <cstdio> here
<stdio.h>= __begin_namespace_std extern int fgetc (file *__stream); extern int getc (file *__stream); __end_namespace_std #define getc(_fp) _io_getc (_fp) <cstdio>= #undef getc
- macro may have side effect leads not use,but can't putforward such occasion getc(_fp) above.
- for safety,maybe can involke
fgetc
rathergetc
or undef macrogetc
manually. getc
weak aliasio_getc
,when macrogetc
not taken effect,the alias function work(eg,in c++ implicitly ).
the comment implies in <stdio.h>
, both getc
, gets
are (function-like) macros. c standard allows this. c++ compiler library code, whatever reason, not want macros exposed c++ program; wants ensure functions invoked.
Comments
Post a Comment