簡體   English   中英

當我嘗試同時包含一些 header 文件時,如何修復錯誤 E0003、C1014?

[英]How can i fix errors E0003,C1014 that occurred when i try to include some header files simultaneously?

話雖如此,我已經嘗試解決網上沖浪的問題,並且發現了一些與我的問題非常相似的問題,但盡管如此,我沒有找到任何解決方案。 我想知道是否有人可以幫助我解決這個問題,解釋什么不起作用,而不是將我重定向到另一個博客。

這里的代碼:

1)文件:list.h

#include "list.c"
#include "element.h"


typedef struct list_element {
    element value;
    struct list_element* next;
} item;
typedef item* list;


list emptyList(void);
boolean empty(list);
element head(list);
list tail(list);
list cons(element, list);
.......
  1. 文件列表.c
    #include "list.h"
    #include <stdio.h>
    #include <stdlib.h>

    list emptyList(void) {
        return NULL;
    }

    boolean empty(list l) {
        if (l == NULL)
            return true; 
        else
            return false;
    }

    list tail(list l) {
        if (empty(l))
            return NULL;
        else
            return l->next;
    }
....

3)文件元素.h

#include "element.c"

#ifndef ELEMENT_H
#define ELEMENT_H

typedef int element;
typedef enum { false, true } boolean;

boolean isLess(element, element);
boolean isEqual(element, element);
element getElement(void);
void printElement(element);
  1. 文件元素.c
#include "element.h"
#include <stdio.h>

boolean isEqual(element e1, element e2) {
    return (e1 == e2); 
}

boolean isLess(element e1, element e2) {
    return (e1 < e2);
}

element getElement() {
    element el;
    scanf(" %d", &el);
    return el;
}

void printElement(element el) {
    printf(" % d", el);
}

然后編譯器給了我錯誤代碼:

 E0003(file #include /../../../../../../element.h includes itself)

和錯誤

code C1014 (too many file of inclusion, depth=1024) for file list.c and element.c```
So I've tried to use the guards (surely in the wrong way) and the error list was almost the same.
I would be grateful if someone could help me out
thank you for the attention.

在您的程序中,您包含.h 文件,其中包含.h 文件,其中包含.c 文件......直到您達到編譯器包含深度級別,在您的情況下為 1024。

消除

#include "element.c"

並刪除

#include "list.c"

*.h文件(頭文件)不應包含任何數據或 function 定義。 這些文件應該只有類型和外部數據聲明、宏定義、function 原型和(當你更高級時) static inline函數定義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM