未知类型名称定义结构

时间:2016-03-19 11:26:46

标签: c struct

我有这个头文件 node.h

#ifndef NODE_H
#define NODE_H

#include <stdio.h>
#include "symboltable.h"
#include "threeaddress.h"
#include "types.h"

typedef struct NODE NODE;
typedef struct LITERALNODE LITERALNODE;

struct NODE {
    INSTRUCTION code;
    SYMBOL_INFO *place;
    NODE *next;
    NODE *previous;
};

struct LITERALNODE {
    TYPE_INFO *typeInfo;
    int integerValue;
    char charValue;
};

LITERALNODE *generateIntegerLiteral(TYPE_INFO *typeInfo, int integerValue);
LITERALNODE *generateCharLiteral(TYPE_INFO *typeInfo, char charValue);
void concatNodes(NODE *node1, NODE *node2);

#endif

node.c 文件

#include "node.h"
#include "types.h"

LITERALNODE *generateIntegerLiteral(TYPE_INFO *typeInfo, int integerValue) {
    LITERALNODE *literalNode;
    literalNode->typeInfo = typeInfo;
    return literalNode;
}

LITERALNODE *generateCharLiteral(TYPE_INFO *typeInfo, char charValue) {
    LITERALNODE *literalNode;
    literalNode->typeInfo = typeInfo;
    return literalNode;
}

void concatNodes(NODE *node1, NODE *node2) {
    node1->next = node2;
    node2->previous = node1;
}

当我尝试编译 node.c 时,我收到以下错误:

node.c:4:1: error: unknown type name 'LITERALNODE'
 LITERALNODE* generateIntegerLiteral(TYPE_INFO* typeInfo, int integerValue) {
 ^
node.c: In function 'generateIntegerLiteral':
node.c:5:2: error: unknown type name 'LITERALNODE'
  LITERALNODE* literalNode;
  ^
node.c:6:13: error: request for member 'typeInfo' in something not a structure or union
  literalNode->typeInfo = typeInfo;
             ^
node.c: At top level:
node.c:10:1: error: unknown type name 'LITERALNODE'
 LITERALNODE* generateCharLiteral(TYPE_INFO* typeInfo, char charValue) {
 ^
node.c: In function 'generateCharLiteral':
node.c:11:2: error: unknown type name 'LITERALNODE'
  LITERALNODE* literalNode;
  ^
node.c:12:13: error: request for member 'typeInfo' in something not a structure or union
  literalNode->typeInfo = typeInfo;

我似乎无法发现自己​​的错误,任何人都可以帮助我。 另外,为什么编译器会对LITERALNODE而不是NODE发表评论,因为它们的构造方式完全相同。

0 个答案:

没有答案