alg*_*lgo 3 c overloading file function
我读到 C 不支持函数重载。但在这张幻灯片中,我们可以看到它是不正确的,我的教授说:“在 C 中,同一个函数名怎么可能有 2 个不同的签名?”
有人可以解释一下吗?
这是不可能的。代码如下:
int open(const char* path, int flags);
int open(const char* path, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
是无效的 C 并且不会编译(但有效的 C++)。
然而,C 支持可变参数函数,旧open函数是使用它来实现的。它实际上声明为:
int open(const char *path, int oflag, ... );
Run Code Online (Sandbox Code Playgroud)
其中...允许通过 的功能使用可变数量的参数stdarg.h。