CTFE output is kind of weired

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 8 15:09:09 PDT 2017


On 07/08/2017 02:29 PM, Andre Pany wrote:

 > I use assert(false, tmp) to see the content of variable tmp as it seems
 > there is no other way in CTFE.

A more natural way is pragma(msg), which you can use in main in this case:

string test(string s)
{
     string tmp = s;
     tmp = tmp[4..$];
     return tmp;
}

enum foo =
`1234
5678
`;

void main()
{
     enum bar = test(foo);
     pragma(msg, bar);
}

 > The output is kind of weired:
 > app.d(6): Error: "1234\x0a5678\x0a"[4..10]
 > app.d(17):        called from here: test("1234\x0a5678\x0a")

Yes, looks pretty weird. :) I remember issues related to Unicode 
characters, which may be fixed by now, but the [4..10] part is news to me.

Ali



More information about the Digitalmars-d-learn mailing list