return the other functions of the void main()

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 9 09:54:56 PDT 2015


On Thursday, 9 April 2015 at 16:02:01 UTC, Dennis Ritchie wrote:
> On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote:
>> Hi,
>> Is it allowed in D similar designs?
>>
>> void main() {
>> 	import std.stdio;
>> 	return writeln("Hello, world!");
>> }
>
> It seems that you can not do so because writeln() something 
> back, which leads to RUNTIME_ERROR in DMD 2.066.1:
>
> OK:
> -----
> import std.conv;
> import std.stdio;
> import std.string;
>
> void main() {
> 	
> 	int n = readln.strip.to!int;
> 	string s = readln.strip;
> 	
> 	foreach (from; 0 .. n)
> 	foreach (jump; 1 .. n) {
> 		bool ok;
> 		foreach (i; 0 .. 5) {
> 			int pos = from + i * jump;
> 			if (pos >= n || s[pos] != '*') {
> 				ok = true;
> 				break;
> 			}
> 		}
> 		if (!ok)
> 			return write("yes");
> 	}
> 	
> 	write("no");
> }
> -----
> http://codeforces.ru/contest/526/submission/10641745?locale=en
>
> RUNTIME_ERROR:
> -----
> import std.conv;
> import std.stdio;
> import std.string;
>
> void main() {
>
> 	int n = readln.strip.to!int;
> 	string s = readln.strip;
>
> 	foreach (from; 0 .. n)
> 		foreach (jump; 1 .. n) {
> 			bool ok;
> 			foreach (i; 0 .. 5) {
> 				int pos = from + i * jump;
> 				if (pos >= n || s[pos] != '*') {
> 					ok = true;
> 					break;
> 				}
> 			}
> 			if (!ok)
> 				return writeln("yes");
> 		}
>
> 	writeln("no");
> }
> -----
> http://codeforces.ru/contest/526/submission/10641695?locale=en

Try running your code somewhere where you can actually see the 
output properly. RUNTIME_ERROR isn't something I recognise from D.


More information about the Digitalmars-d-learn mailing list