本文介绍了如何引用尚未声明的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果我有以下C代码: struct A { struct B * element;} struct B { struct A *元素;} main(){} 如果在声明类型的变量元素时如何编译它struct B *这个类型还没有定义? 如果我在不同的文件中定义了这两个结构,我将如何制作makefile和头文件? : fileA.h: #ifndef _FILEA_H_ #define _FILEA_H_ #include fileB.h struct A { struct B * element;} #endif fileB.h: #ifndef _FILEB_H_ #define _FILEB_H_ #include fileA .h struct B { struct A *元素;} #endif MAKEFILE: CC = gcc CFLAGS = -Wall -g LDFLAGS = -lm all:example program.o:program.c fileA.o:fileA.c fileA.h fileB.o:fileB.c fileB.h 例如:principal.o fileA.o fileB.o $(CC)$(CFLAGS)-o $ @ $ ^ $(LDFLAGS) 你能帮助我吗?在这两种情况下,编译器都不识别结构中的类型,因为它只是稍后定义的。解决方案 (CFLAGS)-o If I have the following C code:struct A{struct B* element;}struct B{struct A* element;}main(){}How do I compile it if when I declare the variable element of type "struct B*" this type wasn't defined yet?And how would I make the makefile and the header files if I had those 2 structs defined in diferent files:fileA.h:#ifndef _FILEA_H_#define _FILEA_H_#include "fileB.h"struct A{struct B* element;}#endiffileB.h:#ifndef _FILEB_H_#define _FILEB_H_#include "fileA.h"struct B{struct A* element;}#endifMAKEFILE:CC = gccCFLAGS = -Wall -gLDFLAGS = -lmall: exampleprogram.o: program.cfileA.o: fileA.c fileA.hfileB.o: fileB.c fileB.hexample: principal.o fileA.o fileB.o$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)Can you guys help me? In both cases the compiler doesn't recognize the type inside the struct because it is only defined later. 解决方案 这篇关于如何引用尚未声明的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 19:17
查看更多