我在 Splint 文档中搜索了“新鲜存储”,并发现了它的提及,但没有正式的定义。我理解并正在使用其他修饰符,例如 null 或 only。我只是不确定什么是新存储。
情况是这样的:
void output_system_information(unsigned int frequency, unsigned int duration) {
unsigned int intervals = duration/frequency;
/* here I allocate some storage */
System * my_system = malloc(sizeof(System));
SystemInfo* current, * total;
if (my_system == NULL) {
fprintf(stderr, "%s\n", "Aborting: failed malloc in output_system_informatioin");
exit(EXIT_FAILURE);
}
/* and here I initialize is in that function */
init_system(my_system);
total = tally_system_info(frequency, duration, my_system);
current = my_system->get_system_info();
/* Here I've removed a ton of print-line statements so that you don't have to see them */
/* then the members and the struct get freed in this here dtor */
delete_system(my_system);
free(current);
free(total);
return;
}
这是一个家庭作业,但这个问题不必直接与家庭作业有关。这是一个夹板问题。