为什么cstdio undef或其他函数
why cstdio undef gets or other functions
当我阅读libstdc++-v3/include/c/cstdio时,我对下面的行很困惑:
//Get rid of those macros defined in <stdio.h> in lieu of real functions.
#undef getc
#undef gets
我认为getc
是一个宏,但gets
是一个函数,事实上,为什么不定义一个函数?可能在某些系统中,它都是在宏中实现的?
更新:我试着把我对<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
- 宏可能有一些副作用,导致我们不使用,但我不能为上面的getc(_fp)提出了这样一个场合。
- 为了安全起见,也许我们可以使用
fgetc
而不是getc
或手动取消宏getc
。 -
getc
是IO_getc
的弱别名,当宏getc
不被使用时生效后,函数的别名将起作用(例如,在c++中隐式地)。
注释清楚地表明,在<stdio.h>
中,getc
和gets
都可以是(类函数)宏。C标准当然允许这样做。c++ 编译器库代码,无论出于何种原因,不希望将宏暴露给c++程序;它要确保函数被调用。
相关文章:
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- C++变量名(可以将 main 声明为变量,但对于其他函数名称则不然)
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 为什么 ADL 的运算符函数行为与其他函数不同?
- 将其他函数中的变量用于主函数C++
- 使用函数打开文件,然后让其他函数利用该文件?
- 如何创建一个函数来执行其中的其他函数
- 是否可以将多个结构作为一个数据包存储在一个函数中,然后传递给其他函数并在那里提取?
- 变量 z 无法从其他函数访问变量 x
- 将 libstdc++ 和其他函数组合到一个库中
- 休眠函数,但不阻止其他函数和代码
- 我的代码只会运行主函数,其他函数不会在C++中编译
- 传递多个参数的功能,该函数将类包含到其他函数
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 如果从在其他函数中调用的函数引发异常会发生什么情况
- 为什么在其他函数中声明的函数不参与参数相关查找?
- C++ - 有没有办法只继承一次某些函数,而其他函数在多次继承中多次继承?
- 我应该删除来自其他函数或类方法的指针吗?
- Windows表单如何使用其他函数回调图表信息
- 关于函数调用,我的程序没有读取我的其他函数。为什么?