Compile time vs run time -- what is the difference?
areYouSureAboutThat
areYouSureAboutThat at gmail.com
Wed Dec 28 09:10:38 UTC 2022
On Wednesday, 28 December 2022 at 02:31:45 UTC, thebluepandabear
wrote:
>
> ..
> Other errors are only able to be spotted during run time such
> as exceptions, dividing by zero, assert blocks.
With regards to the 'assert blocks' you mention, D (like C++) has
both static assert and runtime assert.
// ---
module test;
@safe:
import std;
void main()
{
string val = "some string";
static assert(is(typeof(x) : int)); // assertion fails at
compile time.
assert(val == "some other string"); // assertion fails at
runtime.
}
// ---
More information about the Digitalmars-d-learn
mailing list