Strange cast error in compile-time function

Max Samukha samukha at voliacable.com.removethis
Tue Jul 24 10:58:57 PDT 2007


On Tue, 24 Jul 2007 19:47:39 +0300, Max Samukha
<samukha at voliacable.com.removethis> wrote:

>On Tue, 24 Jul 2007 18:09:18 +0200, Stephan Kochen <stephan at kochen.nl>
>wrote:
>
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>Hello all,
>>
>>I'm stuck on something. I'm writing some compile-time stuff to generate
>>a function that gets me the Unicode general category for a dchar. I have
>>some compile-time functions that read from the TXTs from the Unicode
>>Character Database and create the actual D code for me.
>>
>>The source code is attached.
>>
>>The functions work at run-time and output the correct D code, when I
>>print the string return value using writefln. But when I try to use a
>>mixin to 'paste' it in a function at compile-time, I get a vague error:
>>	"Error: cannot cast int to RowData"
>>(and nothing else.)
>>
>>RowData is a struct I use. It might be interesting to note that this
>>happens with DMD 1.0 (and the GDC based on it), but with DMD 1.020 I get
>>a slightly different (but equally vague) error:
>>	"Error: cannot cast int to char[][]"
>>
>>I've been staring at this for hours. Halp! :)
>>
>>Thanks in advance,
>>- -- Stephan
>>-----BEGIN PGP SIGNATURE-----
>>Version: GnuPG v1.4.6 (GNU/Linux)
>>
>>iD8DBQFGpiQucFUq0gzqDwQRAjz0AJ0ZexMPgBxHxQXBGshI6hghgXDD8ACgspRd
>>GWIHuG9P7iV9k/CNf+bGKsU=
>>=jyR8
>>-----END PGP SIGNATURE-----
>
>There are still bugs in the compiler that make writing compile-time
>functions a difficult task. In your case, the error is caused by
>retval not being explicitly initialized (in parseUnicodeCSV). Try
>
>RowData retval = RowData.init;
>
>But even if it is, the function still cannot be evaluated at
>compile-time. Trying to figure out why.

The compiler doesn't like string-to-null comparison in 'if' (looks
like a compiler bug).  Try to make your algorythm not to rely on it.



More information about the Digitalmars-d mailing list