Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!dcdwest!ittvax!decvax!genrad!panda!talcott!harvard!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: type punning Message-ID: <452@rlgvax.UUCP> Date: Sat, 9-Feb-85 14:15:27 EST Article-I.D.: rlgvax.452 Posted: Sat Feb 9 14:15:27 1985 Date-Received: Mon, 11-Feb-85 04:48:01 EST References: <8125@brl-tgr.ARPA> Organization: CCI Office Systems Group, Reston, VA Lines: 30 > Note the lack of cast on h in Put_Tail. Oh, JHFC, Gary, RTFM. K&R says that the coercion of 0 to a null pointer of the appropriate type is automatic in what amount to all situations where the compiler can figure this out. Stop talking about the lack of casts in statements like "if (!h)"; they never were required and never will be. > Now in the modules where we deal primarily with buffers, Get_Head is > declared as BUFP Get_Head; where we deal with channels, CHANP Get_Head. > And where widgets are used Get_Head is of type WIDGETP. And so on. > Lint will go bonkers over this! OK, where's the good reason (other than fingers tired of typing casts) for type punning? This whole thing can be expressed the same way with casts (if constantly typing casts get in your way, define some macros). ANSI Standard C would permit you to define Get_Head as returning "void *", in which case the casts wouldn't be necessary to silence "lint". The compiler would also know enough to generate correct code. I suspect with a language designed with type inheritance in mind, what you specify could be stated in a much more straightforward fashion (buffers, channels, widgets, etc. inherit the doubly-linked-list nature of lists), and be written in a type-safe fashion. I prefer to let the computer handle all the tedious details, like all correctness checks doable by computer, generation of optimal code, etc., which it can deal with better (given that machines, unlike humans, don't perform less poorly when bored, tired, etc.) than I can. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy