Read files at compile time

Henrik zodiachus at gmail.com
Thu May 31 00:59:35 PDT 2007


Hello! 

I have a question or two regarding what is allowed to be executed at compile time and not. Consider the following:

<code>
import std.stdio;
import std.file;
import std.string;


char[][] loadArchetypes( char[] fileName )
{
    char[][] archetypes = splitlines( cast(char[])read( fileName ) );

    return archetypes;
}


void main()
{
    /// Load archetypes
    const char[][] archetypes = loadArchetypes( "archetypes.txt" );

    foreach( archetype; archetypes )
    {
        writefln( archetype );
    }
}

</code>


I suspect that I am not allowed to do this for some reason. I get the very unhelpful error:
Compiling: fileTest.d
Error: variable useWfuncs is used before initialization
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings


Is it possible to read a file at compile-time in the manner I am trying to do? What does the error message mean?


Yours most confusedly,

Henrik


More information about the Digitalmars-d-learn mailing list