Skip to content

Commit

Permalink
Add assert reference link
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Sep 19, 2016
1 parent abb4ac9 commit e8d4cc7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tutorial01/tutorial01.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static int lept_parse_value(lept_context* c, lept_value* v) {

断言(assertion)是 C 语言中常用的防御式编程方式,减少编程错误。最常用的是在函数开始的地方,检测所有参数。有时候也可以在调用函数后,检查上下文是否正确。

C 语言的标准库含有 `assert()` 这个宏(需 `#include <assert.h>`),提供断言功能。当程序以 release 配置编译时(定义了 `NDEBUG` 宏),`assert()` 不会做检测;而当在 debug 配置时(没定义 `NDEBUG` 宏),则会在运行时检测 `assert(cond)` 中的条件是否为真(非 0),断言失败会直接令程序崩溃。
C 语言的标准库含有 [`assert()`](http://en.cppreference.com/w/c/error/assert) 这个宏(需 `#include <assert.h>`),提供断言功能。当程序以 release 配置编译时(定义了 `NDEBUG` 宏),`assert()` 不会做检测;而当在 debug 配置时(没定义 `NDEBUG` 宏),则会在运行时检测 `assert(cond)` 中的条件是否为真(非 0),断言失败会直接令程序崩溃。

例如上面的 `lept_parse_null()` 开始时,当前字符应该是 `'n'`,所以我们使用一个宏 `EXPECT(c, ch)` 进行断言,并跳到下一字符。

Expand Down

0 comments on commit e8d4cc7

Please sign in to comment.