Strange GCC Behaviour

前端 未结 2 612
野性不改
野性不改 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:33

    This is a long-standing missing optimization in GCC. It should be able to generate the same code for both cases, but it can't.

    Without the constructors, your vertex_type is a POD structure, which GCC can initialize static/global instances of at compile time. With the constructors, the best it can do is generate code to initialize the global at program startup.

提交回复
热议问题