Thread overview
strange compiler error
Feb 27, 2013
Michael
Feb 27, 2013
Ali Çehreli
Feb 27, 2013
Michael
February 27, 2013
dmd extern.d
extern.d(22): Error: undefined identifier r, did you mean template tr(C1, C2, C3
, C4 = immutable(char))(C1[] str, const(C2)[] from, const(C3)[] to, const(C4)[]
modifiers = null)?
extern.d(22): Error: '__error' must be of integral or string type, it is a _erro
r_

dmd extern.d
extern.d(23): Error: undefined identifier r, did you mean variable t?
extern.d(23): Error: '__error' must be of integral or string type, it is a _erro
r_

It was typo. Sample code:

import std.stdio;
import std.typecons;

immutable string externFmt = "extern (C) %s %s (%s);";

enum FnType : ubyte { Unknown, Constructor, Function, GlobalFunction }

Tuple!(string[], FnType) parse(string source)
{
    return tuple(new string[2], FnType.Unknown);
}

void main(string[] args)
{
    writeln(parse(null));

    foreach (line; stdin.byLine())
    {
        auto result = parse(line.idup); // or missed idup
        //auto t = result[1]; // or typo here

        final switch (result[1])
        {
            case FnType.Constructor: break;
            case FnType.Function: break;
            case FnType.GlobalFunction: break;
            case FnType.Unknown: break;
        }
    }
}

is it normal?
February 27, 2013
On 02/27/2013 11:58 AM, Michael wrote:

> enum FnType : ubyte { Unknown, Constructor, Function, GlobalFunction }
>
> Tuple!(string[], FnType) parse(string source)
> {
> return tuple(new string[2], FnType.Unknown);
> }

Sorry, this doesn't answer your question but in general, if you are not going to pass the parameter to another function that requires a 'string', then it is better to define that function parameter as 'const char[]':

Tuple!(string[], FnType) parse(const char[] source)
{
    // ...
}

That way you wouldn't need to call .idup on a mutable argument.

Ali

February 27, 2013
> Sorry, this doesn't answer your question but in general, if you are not going to pass the parameter to another function that requires a 'string', then it is better to define that function parameter as 'const char[]':
>
> Tuple!(string[], FnType) parse(const char[] source)
> {
>     // ...
> }
>
> That way you wouldn't need to call .idup on a mutable argument.
>
> Ali

Oh, thank you very much ;)