我每天都是一名.NET程序员,我正在使用Robert Seacord的Efficient C来学习C语言. 我在第5章-控制流上,它描述了"goto",我正试图编译" list 5-11:使用goto链来释放资源".但是没有定义类型"Object_t". 我以为我只能在其中一个标准标头(stdint.h等)中找到定义,但我找不到它,Stack Overflow和Google搜索也无济于事. 我搜索了这一章和之前的章节,但都无济于事.这是作者在这一点上没有解释的用户定义类型吗?还是我的谷歌搜索有那么糟糕?
我try 了很多我能想到的头文件:
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
下面是函数定义:
int do_something(void) {
FILE *file1, *file2;
object_t *obj;
int ret_val = 0; // Initially assume a successful return value
file1 = fopen("a_file", "w");
if (file1 == NULL) {
ret_val = -1;
goto FAIL_FILE1;
}
file2 = fopen("another_file", "w");
if (file2 == NULL) {
ret_val = -1;
goto FAIL_FILE2;
}
obj = malloc(sizeof(object_t));
if (obj == NULL) {
ret_val = -1;
goto FAIL_OBJ;
}
// Operate on allocated resources
// Clean up everything
free(obj);
FAIL_OBJ: // Otherwise, close only the resources we opened
fclose(file2);
FAIL_FILE2:
fclose(file1);
FAIL_FILE1:
return ret_val;
}
错误是这样的:error: unknown type name ‘object_t’