You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C语言报unterminated conditional directive错误,以下结构体代码哪里有问题?

错误原因

  1. 条件编译块未闭合
    你当前代码只写了头文件保护的起始指令#ifndef T2_H_、#define T2_H_,但整个头文件末尾没有补充对应的#endif来闭合条件编译块,编译器扫描到文件结束都没找到匹配的闭合指令,就会抛出unterminated conditional directive错误,且错误定位会指向条件编译的起始行。
  2. 类型名与变量名冲突
    你已经通过typedef struct adjList{...} adjList;将adjList定义为自定义结构体类型名,后续定义Graph结构体时,成员变量又使用了adjList作为命名,会触发类型与变量名冲突的问题,属于隐藏的语法错误。

修正后的完整代码

#ifndef T2_H_
#define T2_H_
#define SIZE 40

typedef struct node {
    int vertex;
    struct node* list;
} node;

typedef struct adjList{
    node *head_list;
    int visited;
    int arr_name;
} adjList;

typedef struct Graph {
    int tot_vertices;
    // 修改变量名避免和类型名冲突
    struct node** adj_lists; 
} Graph;

// 新增#endif闭合头文件保护
#endif

内容的提问来源于stack exchange,提问作者redmone1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 21:24:00