I am trying to print the value of std::max_align_t in MinGW64. Below is my code:
#include <stdio.h>
#include <cstddef>
int main()
{
printf("max allign: %d\n", alignof(std::max_align_t));
}
When I compile I get the below error:
/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
So I changed to below code:
#include <stdio.h>
#include <cstddef>
int main()
{
printf("max allign: %llu\n", alignof(std::max_align_t));
}
But still I receive below error during compilation:
/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
If I remove 'l' from the printf I get back to same error? How can I resolve the issue.
Since you are using C++ you can go with this
#include <iostream>
#include <cstddef>
int main()
{
std::cout << alignof(std::max_align_t) << '\n';
}