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 rather getc or undef macro getc manually.
  • getc weak alias io_getc ,when macro getc 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

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -