Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site siemens.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!hao!hplabs!tektronix!uw-beaver!cornell!vax135!houxz!houxm!mhuxl!ulysses!allegra!princeton!eosp1!siemens!wws From: wws@siemens.UUCP (William W Smith) Newsgroups: net.lang.c Subject: forward declared structures Message-ID: <226@siemens.UUCP> Date: Mon, 23-Jul-84 08:54:46 EDT Article-I.D.: siemens.226 Posted: Mon Jul 23 08:54:46 1984 Date-Received: Sat, 28-Jul-84 00:37:21 EDT Organization: Siemens RTL Princeton, NJ Lines: 29 I have a question on forward declarations of structures in C. Kernighan and Ritchie does not answer the question and to me the behavior of the Berkeley Unix C compiler is without question wrong. To wit: struct s *ps; main() { struct s { int i1, i2; }; } foo() { ps->i1 = 33; } My question is whether field i1 should be known in foo. In the Berkeley Compiler, it is known if and only if there is a different struct with a field i1 declared before main is declared !? If there is such a field, the type and offset of i1 are correct, otherwise you get an undefined field reference error. I discovered this while implementing a C compiler for a class and wanted to follow real C instead of the simplification of structures that our professor recommended. My solution was to say that the declaration of the structure was exported to the block level of the first use of the forward declaration and no further. Any better ideas? Bill Smith princeton!siemens!wws