← Back to team overview

leaningtech-dev team mailing list archive

[Bug 1393017] Re: error:Field not supported in union.

 

when Cheerp support non-anonymous struct in union i will try it again (hopes new version support win xp)
and in my habit , i always use (A*)  ,not static_cast or reinterpret_cast . so it may cost a lot of time to find all of them.


do you consider define a new cast keyword such as cheerp_cast
when using pure cpp version,i can #define cheerp_cast reinterpret_cast

such as:

struct A
{
 int a;
 int b;
 int c;
};

A test = {123,145,456};
int* _convert = cheerp_cast< int*> (&test);
memcpy(cheerp_cast< char*>_convert , _buffer , sizeof(A));

when meet a cheerp_cast , compiler can collect all conversion in context
, and  generate a local union such as

union cheerp_cast_A
{
    struct
    {
        int a;
        int b;
        int c;
     };
     int cheerp_cast_int[sizeof(A)/sizeof(int)];
     int cheerp_cast_char[sizeof(A)/sizeof(char)];

     inline void fromA(A& in_a)  {  
        a = in_a.a;
        b = in_a.b;
        c = in_a.c;
     }  

      inline void toA(A& out_a)  {  
       out_a.a = a;
       out_a.b = b;
       out_a.c = c;
     }  
};

so the code convert automaticly to follows witch can be supported by
cheerp.

A test = {123,145,456};
cheerp_cast_A _tmp;
_tmp.fromA(test);
int* _convert = _tmp.cheerp_cast_int;
memcpy(_tmp.cheerp_cast_char, _buffer , sizeof(A));
_tmp.toA(test);


I know cheerp memory mode is different from Emscripten. so it may hard for unsafe type code.
but I think code conversion is not a complex thing for a compiler.
if you provide a keyword as such cheerp_cast. the source will be more clearly (avoid using union and memcpy for simple convert ).

-- 
You received this bug notification because you are a member of
Leaningtech Team, which is subscribed to Cheerp.
https://bugs.launchpad.net/bugs/1393017

Title:
  error:Field not supported in union.

Status in Cheerp: C++ for the Web:
  Invalid

Bug description:
  is the error means, cheerp does not support union?

To manage notifications about this bug go to:
https://bugs.launchpad.net/cheerp/+bug/1393017/+subscriptions


References