开发者

0 initialization of C++ built-in types

suppose I have this struct (or class, my question applies to both):

struct builtin 
{ 
    int a;
    int b; 
    builtin() : a(), b(0) { } 
};

I know that both a and b will be initialized to 0开发者_运维问答 by the constructor of builtin. My question is: Is one method faster than the other?


They do the same and take the same amount of time. Also, optimizations on this level are pointless until a profiler proves the opposite. Use what's more readable to you.


Answer: no. The compiled code is identical.


There is no difference in the resulting machine code, only in readability. Here, a is default initialized while b is set to a specific value.

Is that important to show in the source code? Chose the one that make most sense!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜