C - gcc:不带有不同的函数声明/实现的编译器警告 [英] C - gcc: no compiler warning with different function-declaration/implementation
问题描述
函数声明没有参数,而函数声明中没有参数函数实现有参数:
some.h:
void foo();
some.c:
static uint32_t count = 0;
void foo(uint32_t num){
count + = num;
print(Count:%u);
main.c:
foo(100);
foo();
输出:
计数:100
计数:100
编译目标版本:
gcc-arm-none-eabi-4_9-2015q1-20150306 -win32
目标版本的链接器:
gcc-arm-none-eabi-4_9-2015q1-20150306-win32
编译器标志: 像 没有声明一个不带参数的函数,它声明了一个函数, 这意味着你的调用都是正确的,编译器不能真的提醒你。 另一个问题是源文件中的声明实际上与头文件中的声明相匹配,这只是使它更加精确。因此,您不会在那里收到警告或错误。 I try to figure out why my c-compiler gives me no warning/error with following (simplified) code. The function-declaration have no parameters while the function-implementation have parameters: some.h: some.c: main.c: Output: Compiler for target build: Linker for target build: Compiler-Flags: Because of backward compatibility, a declaration like doesn't declare a function that takes no argument, it declares a function which takes an unknown number of arguments of unknown type. That means both your calls are correct, and the compiler can't really warn you about it. The other problematic thing is that the declaration in the source file actually matches the declaration in the header file, it just makes it more precise. Therefore you will not get a warning or error there either. 这篇关于C - gcc:不带有不同的函数声明/实现的编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-Wall -Werror -DuECC_CURVE = uECC_secp256r1 -DMEMORY_CHECK -DDEBUG -Os -g3 -DBACKTRACE
void foo();
void foo();
static uint32_t count = 0;
void foo(uint32_t num) {
count += num;
print("Count: %u");
}
foo(100);
foo();
Count: 100
Count: 100
gcc-arm-none-eabi-4_9-2015q1-20150306-win32
gcc-arm-none-eabi-4_9-2015q1-20150306-win32
-Wall -Werror -DuECC_CURVE=uECC_secp256r1 -DMEMORY_CHECK -DDEBUG -Os -g3 -DBACKTRACE
void foo();