Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!husc6!bbn!rochester!pt.cs.cmu.edu!k.gp.cs.cmu.edu!dwp From: dwp@k.gp.cs.cmu.edu (Doug Philips) Newsgroups: comp.std.c Subject: Typedef names vs. new types. Message-ID: <3355@pt.cs.cmu.edu> Date: 20 Oct 88 03:37:38 GMT Sender: netnews@pt.cs.cmu.edu Organization: Carnegie-Mellon University, CS/RI Lines: 40 Regarding the recent discussion of typedef names and their intent and use: I have found that it can be very useful to use typedef to create a conceptual entity (this is probably an abuse of the mechanism). The problem with this (as mentioned before) is that the compiler doesn't really consider this a new type. Even lint is, at first glance, no help. However, you can somewhat easily get lint to help you out. I'd be interested in finding out what other solutions along these lines people use. My solution is as follows: For convenience, I define all my new typedef names in one place. The rationale is that they often are used to indicate quantities and ranges which are 'configurable' depending on what you want the range of the type to be. This is not a requirement of my solution however. Consider a two dimensional graph where the new typedef'ed names are arranged along the X axis. The Y axis is the "size" of the type. By plotting the points associated with each type/size pair (size is determined by the derivee type), a "type terrain" is visible. What lint can do is tell you, in certain cases, where usage involves elements that are at different altitudes. Particularly useful to me with a 4.2BSD lint is the ability to detect mixture of longs with smaller types. The initial problem is that it is the altitude of the types that makes lint/cc unhappy with their intermixture. What I do is to walk the type terrain, and modify one typedef at a time. If the type is already a long, I make it an int and if it's not a long, I make it one. After each and every transformation I run lint to catch the cases where I'm assigning with mixed types. When I move onto the next type in the terrain I restore the previous type to its original value. The obvious next step is to come up with some way of automating the process so that I'll do it more frequently. -Doug -- Doug Philips "All that is gold does not glitter, Carnegie-Mellon University Not all those who wander are lost..." dwp@cs.cmu.edu -J.R.R. Tolkien