Voldemort toHexString Compile Error

kdevel kdevel at vogtner.de
Sun Mar 17 17:02:31 UTC 2024


On Sunday, 17 March 2024 at 16:48:23 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> [...]
>>> Make Hex static, and it works.
>> 
>> Not really. Have you ever tried?
>> 
>>     "abc äöü߀ D".toHexString.writeln;
>> 
>
> I did run it, both with and without static on Hex.
>
> Without did not work on run.dlang.io which was consistent with 
> the error that Salih had provided.
>
> The error is clear on the first line: "cannot access frame 
> pointer of onlineapp.toHexString.Hex"

I meant the compiled executable, not the compilation. The code 
has an
autodecoding issue which goes unnoticed due to using int (instead 
of
ubyte?) for i. When I run the executable I get a three screens 
stack
trace.

std.conv.ConvOverflowException@[...]linux/bin64/../../src/phobos/std/conv.d(1556): Conversion positive overflow

BTW: What is the purpose of not writing a free function like 
this?:

auto nibbleSplit(ubyte b)
{
   auto MSB = b >> 4;
   auto LSB = b & 15;
   return [MSB, LSB];
}

auto toHexString(string str)
{
   import std.algorithm : map;
   import std.conv, std.range : join;
   import std.utf;

   return str
//            .byCodeUnit // <-- solves the auto-decoding issue
             .map!(e => e.nibbleSplit).join
             .map!(n => n += n > 9 ? '7' : '0')
             .map!(c => c.to!char);
}



More information about the Digitalmars-d mailing list