Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!lavaca.uh.edu!uhnix1!moray!urchin!p4694.f506.n106.z1.fidonet.org!Lynn.Lively From: Lynn.Lively@p4694.f506.n106.z1.fidonet.org (Lynn Lively) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak Message-ID: <10304.25B3EE52@urchin.fidonet.org> Date: 16 Jan 90 18:47:53 GMT Sender: ufgate@urchin.fidonet.org (newsout1.26) Organization: FidoNet node 1:106/506.4694 - Fulcrum's Edge, Spring TX Lines: 51 In an article of <15 Jan 90 03:21:53 GMT>, peter@ficc.uu.net (Peter da Silva) writes: Pd>From: peter@ficc.uu.net (Peter da Silva) Pd>Date: 15 Jan 90 03:21:53 GMT Pd>Organization: Xenix Support, FICC Pd>Message-ID: Pd>Newsgroups: comp.lang.c Pd> Pd>> C has no run-time "type" type. The type value of a typeof construct Pd>> exists only in the mind of the compiler. Pd> Pd>Yes, I know that. This discussion originated with a suggestion that Pd>such Pd>a type be added to the language. It's kind of hard to see how the Pd>semantics Pd>of such a thing could be standardised. What could one do with it at Pd>runtime? Pd> Pd>The discussion about a typeof operator similar to the one in GCC Pd>developed Pd>from that. Peter, Excuse me if I'm answering out of turn, but wouldn't the above require a change in the basic philosophy of memory mapping in C? Seems to me in order to implement such you would need a preamble in front of every field declaring its 'type' and probably its 'size'. You would also need a dynamic symbol table for user defined types via 'typedef'. This would cause a very fundemental change in the way you approached a problem in C and would IMHO cause more harm than good as it would be alow more difficult to do such things as read in an array of 'int's and then turn around and step thru the array with a 'char' pointer. Fields would no longer be layed out in contigious memory, passed parameters to functions would need the preamble also causing alot of overhead for very little return. Seems to me the 'runtime type' is a good job for 'union', don't you think? Something like this. typedef struct { int type; /* Could also use an 'enum' here */ union { [various possible types] } u; } RT_TYPE; Although a compile time 'typeof' would need less overhead (the compiler keeps this information anyway) and would have most of the advantages mentioned previously. I would very much like to see it, if it didn't take away from the power of C in other areas. Your Servant, Lynn