如果我用CC 13.2.0用-std=c17 -Wall -Wextra -Wpedantic
编译下面的代码,尽管在对应"%p"
个格式说明符的参数中没有使用void*
,但我不会收到警告.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
const char cstr[] = "ABC";
size_t size = sizeof cstr;
const uint8_t ustr[] = "ABC";
const int8_t sstr[] = "ABC";
const char* pcstr = cstr;
const uint8_t* pustr = ustr;
const int8_t* psstr = sstr;
printf("cstr ptr: %p\n", cstr);
printf("size ptr: %p\n", (void*)&size); // we need cast to prevent Wformat
printf("&cstr ptr: %p\n", (void*)&cstr); // we also need this cast
printf("pcstr: %p\n", pcstr);
printf("ustr ptr: %p\n", ustr);
printf("pustr: %p\n", pustr);
printf("sstr ptr: %p\n", sstr);
printf("psstr: %p\n", psstr);
return 0;
}
读完问答*What is and how to solve the warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int ’ [-Wformat=] when printing it out后,我应该期待这里的undefined behavior吗?我try 了几次搜索,但您会明白对于如此特定的组合来说,这些搜索有多么困难.
void*
和char-ish*
是否共享上午I点失踪的一些房产,或者这只是海湾合作委员会中missing warnings的 case ?希望这里的有人能够就这个问题提供一些线索.