gpt4 book ai didi

在C99模式下给出编译错误的代码

转载 作者:太空狗 更新时间:2023-10-29 16:13:00 25 4
gpt4 key购买 nike

<分区>

关于测试代码

#include <stdio.h>

int main()
{
char a[5][3];

printf("a = %p\n", a);
printf("&a[0] = %p\n", &a[0][0]);
printf("&a = %p\n", &a);
printf("*a = %p\n", *a);

return 0;
}

它被编译并以 C 模式给出输出(http://ideone.com/KD9Wz1):

a = 0xbfd8ea51
&a[0] = 0xbfd8ea51
&a = 0xbfd8ea51
*a = 0xbfd8ea51

在使用严格的 C99 模式(http://ideone.com/iTACGZ)编译时,会导致编译错误:

prog.c: In function ‘main’:
prog.c:7:10: error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘char (*)[3]’ [-Werror=format]
prog.c:9:10: error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘char (*)[5][3]’ [-Werror=format]
cc1: all warnings being treated as errors

上面的代码在C99中不是有效的吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com