I'm debugging some code that essentially is identical to this:
struct Foo { int a; int b; };
struct Bar { Bar() {} Foo foo{0}; };
Run Code Online (Sandbox Code Playgroud)
When I make an instance of Bar, it seems like both a and b are initialized to zero. Is this guaranteed? Where can I find that in the spec?
我写了这个故意错误的代码
printf("%d %d", 1);
Run Code Online (Sandbox Code Playgroud)
用g++和编译-Werror=format.
编译器给出了令人印象深刻的警告:
error: format '%d' expects a matching 'int' argument [-Werror=format]
Run Code Online (Sandbox Code Playgroud)
据我所知,编译器无法判断代码是错误的,因为格式字符串直到运行时才被解析.
我的问题:编译器是否有一个特殊的功能,可以用于printf和类似的libc函数,或者这是一个我可以用于自己的函数的功能?字符串文字?