Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!apple!vsi1!octopus!sjsumcs!horstman From: horstman@sjsumcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++ Subject: Re: 1 Definition Allowed Message-ID: <1990Nov5.051429.6109@sjsumcs.sjsu.edu> Date: 5 Nov 90 05:14:29 GMT References: <1990Oct30.125546.3702@kodak.kodak.com> <1463@proto.COM> <1990Nov1.202530.15347@cs.columbia.edu> Reply-To: horstman@sjsumcs.SJSU.EDU (Cay Horstmann) Organization: San Jose State University Lines: 24 In article <1990Nov1.202530.15347@cs.columbia.edu> kearns@cs.columbia.edu (Steve Kearns) writes: >E&S (3.1) says only one definition is allowed per program for any >name. It also claims that "struct S { int a; int b; };" is a >definition of a struct. But this seems to imply that such a struct >declaration cannot appear in a header file which will be included in >more than 1 compilation unit!!!!! This is obviously counter to >anyone's intuition, so what gives? > This is NOT what they mean. Yes, you can (and must) have the same struct definition in many different compilation units (i.e. files.) What you cannot have (and that is STUPID) is multiple definitions of the same struct in the same file. While it is perfectly legal to have fifteen declarations of extern int x; or int foo(int);, and the compiler will happily check for consistency, it is not legal to have two occurrences of struct Complex { double re,im; }; in the same file. I wish this were remedied. One of the best pieces of advice I know is TO INCLUDE EACH HEADER FILE IN ITS OWN .C FILE, but it just doesn't work for structs, enums, and typedefs. It does not appear too difficult to check. I agree that checking consistency of inline functions is probably unreasonable, and a redefinition error is reasonable there. Cay