c语言 难点,C语言内存调试技巧—C语言最大难点揭秘

以下是引用片段:

/********

* ...

*

* Note that any function invoking protected_file_read()

* assumes responsibility eventually to fclose() its

* return value, UNLESS that value is NULL.

*

********/

FILE *protected_file_read(char *filename)

{

FILE *fp;

fp = fopen(filename, "r");

if (fp) {

...

} else {

...

}

return fp;

}

/*******

* ...

*

* Note that the return value of get_message points to a

* fixed memory location.    Do NOT free() it; remember to

* make a copy if it must be retained ...

*

********/

char *get_message()

{

static char this_buffer[400];

...

(void) sprintf(this_buffer, ...);

return this_buffer;

}

/********

* ...

* While this function uses heap memory, and so

* temporarily might expand the over-all memory

* footprint, it properly cleans up after itself.

*

********/

int f6(char *item1)

{

my_class c1;

int result;

...

c1 = new my_class(item1);

...

result = c1.x;

delete c1;

return result;

}

/********

* ...

* Note that f8() is documented to return a value

* which needs to be returned to heap; as f7 thinly

* wraps f8, any code which invokes f7() must be

* careful to free() the return value.

*

********/

int *f7()

{

int *p;

p = f8(...);

...

return p;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值