我正在尝试打印MinGW64中std::max\u align\u t的值。下面是我的代码:
#include <stdio.h>
#include <cstddef>
int main()
{
printf("max allign: %d\n", alignof(std::max_align_t));
}
编译时,出现以下错误:
/c/tools/mingw64/bin/c++.exe test23.cpp -Wall -ftrack-macro-expansion=0 -Werror -std=gnu++14 -Og -g3 -o test23.exe -Wl,--out-implib,test23.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
test23.cpp: In function 'int main()':
test23.cpp:6:57: error: format '%d' expects argument of type 'int', but argument 2 has type 'long long unsigned int' [-Werror=format=]
printf("max allign: %d\n", alignof(std::max_align_t));
^
cc1plus.exe: all warnings being treated as errors
因此,我改为以下代码:
#include <stdio.h>
#include <cstddef>
int main()
{
printf("max allign: %llu\n", alignof(std::max_align_t));
}
但在编译过程中,我仍然收到以下错误:
/c/tools/mingw64/bin/c++.exe test23.cpp -Wall -ftrack-macro-expansion=0 -Werror -std=gnu++14 -Og -g3 -o test23.exe -Wl,--out-implib,test23.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
test23.cpp: In function 'int main()':
test23.cpp:6:59: error: unknown conversion type character 'l' in format [-Werror=format=]
printf("max allign: %llu\n", alignof(std::max_align_t));
^
test23.cpp:6:59: error: too many arguments for format [-Werror=format-extra-args]
cc1plus.exe: all warnings being treated as errors
如果我从printf中删除“l”,我会返回到相同的错误?如何解决此问题。