Purpose of Unions in C and C++

后端 未结 16 2172
予麋鹿
予麋鹿 2020-11-22 06:55

I have used unions earlier comfortably; today I was alarmed when I read this post and came to know that this code

union ARGB
{
    uint32_t colour;

    str         


        
16条回答
  •  再見小時候
    2020-11-22 07:44

    In C++, Boost Variant implement a safe version of the union, designed to prevent undefined behavior as much as possible.

    Its performances are identical to the enum + union construct (stack allocated too etc) but it uses a template list of types instead of the enum :)

提交回复
热议问题