Strange GCC Behaviour

前端 未结 2 613
野性不改
野性不改 2021-02-05 09:44

Given the following C++ code:

struct vertex_type {
    float x, y, z;

    //vertex_type() {}
    //vertex_type(float x, float y, float z) : x(x), y(y), z(z) {}
         


        
2条回答
  •  旧巷少年郎
    2021-02-05 10:26

    If you have custom constructor, the compiler should call it for all vector it create. If you don't write your own, it default to a generated constructor. But as no type are complex, it just don't need to call it. And the array is store as a constant table in the binary.

    Try inlining your default constructor and let it empty. Of course, it may only work wit h optimization enabled

提交回复
热议问题