has initializer but incomplete type
Bonjour, voila,j'essaye pour la première fois l'utilisation des unions. Et je tombe sur un magnifique bug dont je ne trouve pas a solution :
Code:
1 2 3 4 5
|
test-exp.c: In function «main":
test-exp.c:9: erreur: variable «x" has initializer but incomplete type
test-exp.c:9: erreur: invalid application of «sizeof" to incomplete type «expression"
test-exp.c:9: erreur: storage size of «x" isn"t known |
Je vous présente donc mes 3 fichier responsable de l'erreur, j'ai un fichier main et les fichier expression.h et expression.c
Code:
1 2 3 4 5 6 7 8
|
#include <stdlib.h>
#include "expression.h"
int main(int argc,char **argv){
expression x = malloc(sizeof(expression));
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#ifndef EXPRESSION_H
#define EXPRESSION_H
/*
expression est :
- soit une valeur entiere
- soit un noeud ayant :
-- pour sommet un operateur
-- et pour membre gauche et droite :
--- soit une valeur entiere
--- soit une expression
*/
typedef struct expression expression;
/*
Les opérateurs sont
egal, diff, sup, inf, supegal, infegal
affect, plus, moins, fois, divise
*/
typedef enum operateur operateur;
#endif /* EXPRESSION_H */ |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include "expression.h"
enum operateur {
egal, diff, sup, inf, supegal, infegal,
affect, plus, moins, fois, divise
};
typedef struct noeud {
operateur sommet;
expression *gauche;
expression *droite;
} noeud;
struct expression {
int type; // 1 pour entier, 2 pour noeud.
union {
noeud noeud_val;
int int_val;
} data;
}; |
Si quelqu'un à la solution à mon problème, merci d'avance.