Talk:Hello Plus Plus/Compiler

From Esolang
Jump to navigation Jump to search
>else { // CS0165 fix, this wouldn't happen unless your processor is on fire
It would happen if args.length is not 1 and not 2. So it does happen if args.length is 3.
Of course, you check that with "if (args.Length != 1 && args.Length != 2) {". But the compiler does not know that ;)

You could instead just write

string sourceFilename = "";
string outputFilename = "";

and forget the unnecessary else.

-- Feuermonster 16:25, 17 March 2010 (UTC)

If args.Length is not 1 or 2, the else block wouldn't be reached:
			if (args.Length != 1 && args.Length != 2) {
				Console.WriteLine("Hello++ .NET Compiler by Propeng");
				Console.WriteLine("Usage: {0} <source> [destination]",
					Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
				Environment.Exit(1);
			}
-- Propeng 09:50, 19 March 2010 (UTC)
I already mentioned that with "Of course, you check that with "if (args.Length != 1 && args.Length != 2)". But the compiler does not recognize
1.) the Environment.Exit(1);
2.) args.Length is not known at compile time, so since Environment.Exit(1) does not stop the "control flow" of a function, there is actually a case where args.Length could be 3 or 4 or ... (because Environment.Exit(1) might do nothing..). If you would have used "return" instead of Environment.Exit(1) you wouldn't have had any problem.
(I hope my english is not that bad...) Feuermonster 16:55, 19 March 2010 (UTC)