Compile time vs run time -- what is the difference?
areYouSureAboutThat
areYouSureAboutThat at gmail.com
Wed Dec 28 21:48:19 UTC 2022
On Wednesday, 28 December 2022 at 12:42:24 UTC, thebluepandabear
wrote:
>
> Before even running the code I get an IDE warning (IntelliJ).
> Does IntelliJ compile the code in the background?
It will NOT compile successfully unless you do one of these
things:
(1) ensure the result of the 'static assert' is true.
(2) comment out the static assert.
Once you do either of (1) or (2) above, it will compile to an
executable format.
When you execute it, the runtime will catch the 'assert' failure
(ie. assertion == false), and the runtime will bring your program
to an immediate halt.
This was just meant to be an example of differentiating compile
time from runtime, as per you question.
With static assert, your logic testing is traversed during
compilation, and your compilation will come to a stop when the
assertion is found to be false, whereas your asserts are
traversed during program execution, and if they are found to be
false, your program comes to a stop.
https://dlang.org/spec/version.html#static-assert
https://tour.dlang.org/tour/en/gems/contract-programming
More information about the Digitalmars-d-learn
mailing list