小编XPl*_*mer的帖子

initializing struct with {0}

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?

c++ initialization

8
推荐指数
1
解决办法
99
查看次数

-Werror = format:编译器如何知道

我写了这个故意错误的代码

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函数,或者这是一个我可以用于自己的函数的功能?字符串文字?

c c++ compiler-construction libc

6
推荐指数
2
解决办法
2620
查看次数

标签 统计

c++ ×2

c ×1

compiler-construction ×1

initialization ×1

libc ×1