Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++ why isn't "assert" a keyword?

Now "static_assert" is a keyword in C++0x I thought it would be logical to replace the C "assert" macro with an "assert" keyword too.

like image 811
Ricky65 Avatar asked Jun 02 '11 17:06

Ricky65


1 Answers

static_assert is interpreted at compile time so it has to be a keyword so the compiler can process it.

assert doesn't need to be a keyword, and it doesn't make much sense to make it one, since there are many ways a program might want to respond to assertion success or failure. Therefore, it makes more sense to implement it in a library, and it is typically implemented as a macro.

like image 200
Lawrence McAlpin Avatar answered Sep 21 '22 13:09

Lawrence McAlpin