Well, basically that's what I need :
extern
(al) char *
variableCode :
import std.stdio;
import std.string;
import core.stdc.stdlib;
extern (C) int yyparse();
extern (C) extern __gshared FILE* yyin;
extern (C) extern __gshared char* yyfilename;
void main(string[] args)
{
string filename = args[1];
auto file = File(filename, "r");
yyfilename = toStringz(filename);
yyin = file.getFP();
yyparse();
}
However, the toStringz
function returns this error :
main.d(15): Error: cannot implicitly convert expression (toStringz(filename)) of type immutable(char)* to char*
Any idea what's going wrong?
The problem is that yyfilename
, and the return value of toStringz
when it is passed a string, have different const qualifiers. filename
is immutable (D string
is an alias to immutable(char)[]
), however yyfilename
does not have any const qualifier, and is thus mutable.
You have two options:
yyfilename
will not bemodified elsewhere in your program, you should declare it as const(char)*
instead of char*
.filename
when converting it: toUTFz!(char*)(filename)
.