小编red*_*gon的帖子

为什么gcc允许将参数传递给定义为不带参数的函数?

我不明白为什么这段代码会编译?

#include <stdio.h>
void foo() {
    printf("Hello\n");
}

int main() {
    const char *str = "bar";
    foo(str);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

gcc甚至没有发出警告,我向foo()传递了太多的参数.这是预期的行为吗?

c gcc compiler-errors

73
推荐指数
4
解决办法
4961
查看次数

标签 统计

c ×1

compiler-errors ×1

gcc ×1