为什么男人2开说呢? [英] Why does man 2 open say this?
问题描述
我就遇到了这个问题,同时输入 2人开
。它说,有两种开一具有两个指定参数时,和一个具有三个!我最后一次检查,他们是如何做到这一点,我们不能超载在C函数?他们才写C ++?
INT开放(常量字符*路径,诠释标志);
INT开放(常量字符*路径,INT标志,mode_t模式);
没有,他们只是使用可变参数函数。
INT开放(常量字符*路径,诠释旗帜,...);
这使得最后一个参数模式
可选。原型仅示出如何功能应该使用,而不是实际接口
当然,不像真正的超载,编译器不能键入检查的模式
参数,所以用户必须要格外小心,以确保只有2个或3个参数传递和第三参数必须是一个 mode_t
。
顺便说一句,如果你检查 2人开
为BSD(包括OS X)它显示的<一个href=\"https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/open.2.html\">correct原型如上。
I ran into this question while typing man 2 open
. It says that there are two kinds of open, one with two args, and one with three! last time i checked we could not overload functions in C. How did they do this? did they write in C++?
int open(const char * pathname, int flags);
int open(const char * pathname, int flags, mode_t mode);
No, they just used variadic function.
int open(const char * pathname, int flags, ...);
This makes the last argument mode
optional. The prototypes only show how the function should be used, not the actual interface.
Of course, unlike real overloading, the compiler cannot type-check the mode
argument, so the user have to be extra careful to ensure only 2 or 3 arguments are passed, and the 3rd argument must be a mode_t
.
BTW, if you check the man 2 open
for BSD (including OS X) it shows the correct prototype as above.
这篇关于为什么男人2开说呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!