Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!elroy.jpl.nasa.gov!cit-vax!wen-king From: wen-king@cit-vax.Caltech.Edu (King Su) Newsgroups: comp.lang.c Subject: Re: forward references in typedefs (puzzling) Message-ID: <11341@cit-vax.Caltech.Edu> Date: 22 Jul 89 23:23:32 GMT References: <55480@tut.cis.ohio-state.edu> <1196@cbnewsl.ATT.COM> Reply-To: wen-king@cit-vax.UUCP (Wen-King Su) Organization: California Institute of Technology Lines: 39 In article <1196@cbnewsl.ATT.COM> dfp@cbnewsl.ATT.COM (david.f.prosser) writes: >The main advantage gained by separating the typedef declaration from the while headers for particular modules can contain the complete structure. structure must include the detailed header. I have often wondered about this. Is it legal? Since pointers for different data objects are not required to have the same binary format or even storage size, how would a compiler allocate space and initialize a pointer of an unknown type? Consider: master_header.h: typedef struct s1 S1; typedef struct s2 S2; typedef struct s3 S3; one_program_file.c: #include "master_header.h" struct s3 { S1 *pointer_s1; S2 *pointer_s2; int a; .... } s; When compiling "one_program_file.c", how does the compiler figure out the size of 's' and the offset of 'a', given that 'pointer_s1' and 'pointer_s1' are of unknown size. How does the compiler initialize 's' (assuming static variable) if the format for the pointers are unknown. Or is it true that pointers to structures are always of the same size and format? -- /*------------------------------------------------------------------------*\ | Wen-King Su wen-king@vlsi.caltech.edu Caltech Corp of Cosmic Engineers | \*------------------------------------------------------------------------*/