在函数调用中,传递给参数的格式不正确也会带来意想不到的错误,编译器只警告,但执行时发生
./test_printf
Segmentation fault
警告信息如下:
gcc -m32 -o test_printf my_printf.c
my_printf.c:66:12: warning: multi-character character constant
my_printf.c: In function ‘main’:
my_printf.c:66: warning: passing argument 1 of ‘push_test’ makes pointer from integer without a cast
my_printf.c:14: note: expected ‘const char *’ but argument is of type ‘int’
经检查后,函数在调用过程中,传递给的实参格式不正确;
push_test('abc',123,per,'C',2.79);
调用过程中,本应该打双引号的字符串,打成了单引号;造成传递格式错误。所以才会警告多字符的字符常量。但是后面一个警告就不知道为什么了。
格式改回后无警告,程序正常执行。
本文记录了一次函数调用中因参数传递格式错误导致的警告及解决过程。错误来源于使用单引号代替双引号来定义字符串,导致编译器警告。
2080

被折叠的 条评论
为什么被折叠?



