How to use assert to evaluated at compile time in C++

1 Answer

0 votes
#include <iostream>
#include <cassert>

int main() {
    assert(7 + 8 == 15);
    std::cout << "7 + 8 == 15 OK\n";
    
    assert(7 + 8 == 16);
    std::cout << "7 + 8 == 16 OK\n";
}


// main.cpp:8: int main(): Assertion `7 + 8 == 16' failed.
// Command terminated by signal 6


/*
run:


*/

 



answered Apr 26, 2023 by avibootz

Related questions

2 answers 162 views
1 answer 125 views
1 answer 152 views
...