Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* Adator. prog.
  + feladatsor
  + quick link

Teaching

* Prog. for Data Sci.
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

assert

(1) assert
import std.stdio;

int add(const int a, const int b) pure
{
    assert(a > 0);
    // assert(a > 0, "`a` must be positive");
    return a + b;
}

void main()
{
    writeln(add(-2, 3));
}

Compile and run:

$ dmd main.d

$ ./main
core.exception.AssertError@main.d(7): Assertion failure
...

Disable assertions:

$ dmd main.d -release

$ ./main
1

Notes:

  • In release mode, assertions are ignored. The compiler simply drops those lines.
  • However, there is one exception. assert(0) (and assert(false), they're equivalent) is NOT ignored in release mode! Why? Because it indicates a part of the program that execution should never reach. If execution reaches that part, then it's a problem that mustn't be ignored.
  • Assertions shouldn't have any side effects, so they can be used in pure functions.
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 September 06, 18:12