-3
Warning: This challenge is only valid for languages with a compiler.
Make a program (which is perfectly valid code) that outputs Hello, World
, even before runtime.
How? Let me explain.
Many languages have a compiler. Some operations are made in the compile-time, and others, in runtime. You trick the compiler to output the text Hello, World
in compile-time. The text can be anywhere, like the build log.(Not errors. sorry for invalidating all those answers. at least theres pragma tho)
You can use C, C++ or C#, but I wouldn't encourage you to. It's simply a game breaker.
p.s. I wrote this challenge because the tag compile-time is both unused, and used wrong.
9Wouldn't the simple source code
Hello, World!
be optimal in almost any compiled language where that line is not valid code and the offending line gets printed in an error message? – Martin Ender – 2017-07-05T09:15:18.3734"which is perfectly valid code" ... "The text can be anywhere, like the build log, an error, anywhere" ... what's "perfectly valid code" then? – Martin Ender – 2017-07-05T09:22:02.917
1I would say, better ask the “Hello, World!” to appear both when compiling and when running. That would make clear what is valid code. – manatwork – 2017-07-05T09:25:46.570
@manatwork Or use two different strings so that you can't just get the line output during compiling that has the string for the actual running. – Martin Ender – 2017-07-05T09:26:26.510
I have to agree with @MartinEnder. Almost all programming languages with a compiler will output the incorrect source code with an error class/function/something is missing. Just take my posted Java answer for example. This would be a valid answer in almost all programming languages with a compiler.. So although I barely do this, I give this a -1 vote for being boring, straight-to-the-point in more than 90% of the the compiler languages, and kinda pointless challenge. Sorry.. – Kevin Cruijssen – 2017-07-05T09:26:55.420
1Are custom file names allowed? – Okx – 2017-07-05T10:53:12.450
Does the code have to compile to an executable or is an object file enough? – Dennis – 2017-07-05T21:02:23.827
This would've been cool, but you didn't spend much time on the question :(. – Magic Octopus Urn – 2017-07-11T21:26:06.863