Skip to content

Instantly share code, notes, and snippets.

@cbecerescu
Last active November 1, 2019 20:29
Show Gist options
  • Save cbecerescu/9a114bb92b23bd8e275a8eae08c6cc2f to your computer and use it in GitHub Desktop.
Save cbecerescu/9a114bb92b23bd8e275a8eae08c6cc2f to your computer and use it in GitHub Desktop.

Consider the following C header:

struct A_struct {
    union {
        int a;
        struct {
            int b;
            union {
                int c;
                char d;
            };
        };
    };
};

Dpp would translate it to:

extern(C)                                                                      
{                                                                              
    struct A_struct                                                            
    {                                                                          
        static union _Anonymous_0                                              
        {                                                                      
            int a;                                                             
            static struct _Anonymous_1                                         
            {                                                                  
                int b;                                                         
                static union _Anonymous_2                                      
                {                                                              
                    int c;                                                     
                    char d;                                                    
                }                                                              
                _Anonymous_2 _anonymous_3;                                     
                auto c() @property @nogc pure nothrow { return _anonymous_3.c; }
                void c(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_3.c = val; }
                auto d() @property @nogc pure nothrow { return _anonymous_3.d; }
                void d(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_3.d = val; }
            }
            _Anonymous_1 _anonymous_4;                                         
            auto b() @property @nogc pure nothrow { return _anonymous_4.b; }   
            void b(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_4.b = val; }
                                                                               
            auto c() @property @nogc pure nothrow { return _anonymous_4.c; }   
            void c(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_4.c = val; }
                                                                               
            auto d() @property @nogc pure nothrow { return _anonymous_4.d; }   
            void d(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_4.d = val; }
        }                                                                      
        _Anonymous_0 _anonymous_5;                                             
        auto a() @property @nogc pure nothrow { return _anonymous_5.a; }       
        void a(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_5.a = val; }
                                                                               
        auto b() @property @nogc pure nothrow { return _anonymous_5.b; }       
        void b(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_5.b = val; }
                                                                               
        auto () @property @nogc pure nothrow { return _anonymous_5.; }         
        void (_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_5. = val; }
    }                                                                          
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment