Unions and CTFE

Gianni Pisetta via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 18 12:05:12 PST 2015


On Friday, 18 December 2015 at 17:21:39 UTC, Jimmy Cao wrote:
> On Friday, 18 December 2015 at 14:30:25 UTC, Gianni Pisetta 
> wrote:
>> Hi all,
>> i'm coding a parametrized crc implementation that can support 
>> most of the standards. I want to make it work with CTFE and i 
>> stumbled upon a difficulty when using 
>> std.bitmanip.nativeToLittleEndian and 
>> std.bitmanip.nativeToBigEndian.
>> The code below is the concept used by EndianSwapper and it 
>> does not compile because of unions and CTFE. Also as the error 
>> message is very obscure, is it intended behaviour or a bug?
>
> I think it's intended behavior.  According to 
> http://dlang.org/changelog/2.065.0.html#ctfe-overlapped-field
>
> "Bit image reinterpretation by using two overlapped union 
> fields is not allowed during CTFE."

Yeah, i supposed it. But the error message was misleading, 
because 'data' is initialized and 'bytes' is the actual 
uninitialized part. I guess the error message can be improved. 
Anyway thanks


More information about the Digitalmars-d mailing list