D and file names

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 25 04:47:45 PDT 2011


On Fri, 25 Mar 2011 07:27:10 -0400, Russel Winder <russel at russel.org.uk>  
wrote:

> On Fri, 2011-03-25 at 13:10 +0200, Vladimir Panteleev wrote:
>> On Fri, 25 Mar 2011 13:05:39 +0200, Russel Winder <russel at russel.org.uk>
>> wrote:
>>
>> > It appears that DMD barfs on files with - in the file name.  Why?
>>
>> Do you mean, why doesn't DMD try to work around the problem  
>> automatically
>> (e.g. by substituting/removing invalid characters in the module
>> identifier)? The error message answers your verbatim question.
>
> - is a perfectly valid character in a file name, well on Posix compliant
> systems anyway.  The question is why D, aping Java, imposes restrictions
> when there is no need.

Every character except '/' is valid in a file name.  In D, the module name  
must be a valid symbol, and also the name of the file you import to get  
that module.

It's as simple as "don't name your files with non-valid symbol  
characters."  It's the way the language is designed, and if that's too  
much of a burden, then don't use the language.

>> "test-file-name.d: Error: module test-file-name has non-identifier
>> characters in filename, use module declaration instead"
>
> The real irritant for me is that the file in question has one function,
> main,  there is nothing to do with modules going on here.

Every compiled d file is a module, the compiler uses the file name if you  
don't provide one.  Note it is not advisable to name your modules  
differently than the file name, because the module name is also used to  
import the file.  This means, if you named a file differently from a  
module, importing the module will fail to find it.  However, standalone  
single-file programs should not be an issue.

This should compile:

test-file-name.d:

module testfilename;

void main()
{}

-Steve


More information about the Digitalmars-d mailing list