Is it possible to set/override the name of the source file when piping it into DMD via stdin?

H. S. Teoh hsteoh at qfbox.info
Wed Dec 13 20:02:33 UTC 2023


On Wed, Dec 13, 2023 at 11:58:42AM -0800, H. S. Teoh via Digitalmars-d-learn wrote:
[...]
> Add a module declaration to your source file. For example:
> 
> 	echo 'module abc; import std; void main(){writefln(__MODULE__);}' | dmd -run -
> 
> Output:
> 	abc
> 
> `__stdin` is used as a placeholder when no module declaration is
> present, and dmd doesn't know the filename (which is what it would
> normally have used for the module name in this case).
[...]

Hmm, apparently the module declaration doesn't change the placeholder
filename. Using `#line 1 abc.d` does the trick, as Adam suggests.


T

-- 
People tell me I'm stubborn, but I refuse to accept it!


More information about the Digitalmars-d-learn mailing list