Date: Mon, 21 Oct 1996 17:20:58 +0200 (MESZ) From: "Hr.Ladavac" <lada@ws2301.gud.siemens.co.at> To: wollman@lcs.mit.edu (Garrett Wollman) Cc: jdp@polstra.com, michaelh@cet.co.jp, current@freebsd.org Subject: Re: <sys/queue.h> Message-ID: <199610211520.AA119551258@ws2301.gud.siemens.co.at> In-Reply-To: <9610211437.AA10256@halloran-eldar.lcs.mit.edu> from "Garrett Wollman" at Oct 21, 96 10:37:39 am
next in thread | previous in thread | raw e-mail | index | archive | help
E-mail message from Garrett Wollman contained: > > <<On Sun, 20 Oct 1996 19:37:04 -0700, John Polstra <jdp@polstra.com> said: > > > True, but that's not the point. The point is, at a certain level, > > a type is a type is a type. You shouldn't have to know whether > > it's represented as a struct or as a union or as an array. By > > using a typedef you enforce not knowing the details of the > > representation, making it easier to change that representation in > > the future without having to change a bunch of code. > > Actually, no. typedefs are the ultimate in un-opaqueness. In the C > programming language, I can utter `struct foo' without knowing how > such a structure is defined. I cannot utter `blurfl_t' without it > having previously be defined somewhere. Furthermore, it is not > permissible to twice utter `typedef struct bar bar_t' in a C program. > > The absolute worst-structured program I know (ISI RSVPD) was written > in the `spaghetti typedef' style, and as a result all of its header > files are so entangled with each other that every source file in the > program must include all of them, even in the absence of any > declarations relevant to that source file. I was able to dramatically > clean this up in the version I was working on by simply eliminating > all the typedefs and referring to the structures by their proper tags > (after inventing tags for them) as bwk and dmr intended. You have a point, as long as the 'struct foo' remains a struct ... and then someone changes that into a 'union foo' ... Moreover, uttering 'typedef struct foo foo_t' in a public header file once should be enough (the header file of the component implementing the methods over foo_t.) IIRC, X11 people had no problems with that. Some discipline in physical layout of your implementation is needed (the downside of foo_t approach)--otherwise you get code that includes the whole world millions of times (which does some bad things to the compilation time). The fact that you cannot use typedef as a forward reference should be regarded as a C language defficiency. BTW, this is not intended as a flame-fest fuel. /Marino
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610211520.AA119551258>
