Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Update S-Expressions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed May 18, 2016
1 parent 961557e commit f87e2b2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions S-Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ typedef struct lval {

我们可以重写 `lval` 的构造函数,使其返回 `lval` 的指针,而不是其本身。这样做会使得对 `lval` 变量进行跟踪更加简单。为此,我们需要用到 `malloc` 库函数以及 `sizeof` 操作符为 `lval` 结构体在堆上申请足够大的内存区域,然后使用 `->` 操作符填充结构体中的相关字段。

当我们构造一个 `lval` 时,它的某些指针字段可能会包含其他的在堆上申请的内存,所以我们应该小心行事。当某个 `lval` 完成使命之后,我们不仅需要删除它本身所指向的堆内存,还要删除它的字段所指向的堆内存。

```
/* Construct a pointer to a new Number lval */
lval* lval_num(long x) {
Expand Down

0 comments on commit f87e2b2

Please sign in to comment.