Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!watmath!rbutterworth From: rbutterworth@watmath.UUCP (Ray Butterworth) Newsgroups: comp.lang.c Subject: Re: Structure type mismatch Message-ID: <6869@watmath.UUCP> Date: Sun, 12-Apr-87 13:33:55 EST Article-I.D.: watmath.6869 Posted: Sun Apr 12 13:33:55 1987 Date-Received: Sat, 18-Apr-87 19:27:36 EST References: <6821@brl-adm.ARPA> Organization: U of Waterloo, Ontario Lines: 35 In article <6821@brl-adm.ARPA>, dsill@NSWC-OAS.arpa writes: > Try this instead: > struct { int a,b; } structtype; > struct structtype foo() { struct structtype c; return c; } Better yet, try this: #include "foo.h" FooType foo() { FooType c; return c; } where "foo.h" contains: typedef struct { int a; int b; } FooType; extern FooType foo(); Then the function that calls foo() can include foo.h too and not have to define the structure a third time. It also means that if you want to add an extra field to the foo structure, you need only make the change in one very obvous place. Putting the extern into the header file means that you don't have to declare the function in every file that uses it, and that if you should declare it incorrectly somewhere, the compiler will let you know about it. Another point of style I've learned to avoid is the use of commas in declarations. e.g. instead of "int a,b;" I always use "int a; int b;". In the case of int it doesn't really matter, but if it were "struct foo *a,*b;" and at some time in the future we decided to get rid of struct foo* and replace it with TypeFooPtr, it makes it a lot easier when changing the hundreds of declarations of "struct[ ][ ]*foo[ ]*\*[ ]" to "TypeFooPtr ". (The brackets contain blank and tab.) With the comma list you have to do this by hand.