www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why does the following program write the message 'Foo' twice?

reply "Gary Willoughby" <dev nomad.so> writes:
Why does the following program write the message 'Foo' twice?

void main(string[] args)
{
	pragma(msg, "Foo");
}
Mar 19 2014
next sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 19 March 2014 at 10:08:50 UTC, Gary Willoughby 
wrote:
 Why does the following program write the message 'Foo' twice?

 void main(string[] args)
 {
 	pragma(msg, "Foo");
 }
The message is not printed by the program, but by the compiler. If you build the program via dmd, the message is only printed once. If you use rdmd, it will be printed twice, because rdmd invokes dmd once to gather the program's dependencies, and a second time to actually build the program.
Mar 19 2014
parent "Gary Willoughby" <dev nomad.so> writes:
On Wednesday, 19 March 2014 at 10:10:18 UTC, Vladimir Panteleev 
wrote:
 If you use rdmd, it will be printed twice, because rdmd invokes 
 dmd once to gather the program's dependencies, and a second 
 time to actually build the program.
Yes i'm using rdmd. Thanks.
Mar 19 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Wednesday, 19 March 2014 at 10:08:50 UTC, Gary Willoughby
wrote:
 Why does the following program write the message 'Foo' twice?

 void main(string[] args)
 {
 	pragma(msg, "Foo");
 }
Once upon compilation and once upon run-time. I don't know if it is intended design but this is how `pragma(msg)` works if put into function body.
Mar 19 2014
parent "Dicebot" <public dicebot.lv> writes:
Disregard my comment, Vladimir is right :)
Mar 19 2014