Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!purdue!bu.edu!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Message-ID: <5263@buengc.BU.EDU> Date: 13 Jan 90 22:09:38 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 38 In article <-K016ODxds13@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: >and Discredits someone else: >> This last sentence bothers me. It would be quite simple to implement >> a C operator such as "(typeof) x" that returns some representation of >> the type of the variable x. > >I think this would be a worthwhile innovation, and one that's as easy >to implement as sizeof. It wouldn't return a value, but would be used >anywhere a type could be used. > >I realise this isn't quite what's meant here. An operator to return >some indication of the type of an object would be useful, but I'm not >sure what it'd return. A small integer? A structure? A pointer to a >structure? The "type" of a C object can be very complex... what would >it return for: Where's the struct identifier? | > struct { > union uabc { [...edited for television...] > } x; Well, since you didn't give it a name, I'd expect it would make one up and plop it on the symbol table. And then when you asked for typeof x, it would give back `struct _T_aaa' or something similar. >But a typeof operator... wouldn't that be something... > >#define SWAP(a,b) {typeof a tmp; tmp=a; a=b; b=tmp} Oboy. Saved a few char's in the source code... --Blair "But what would it return for `typeof( &a + &b )'? or is that too daffy an idea? Hi, Doug.:-)"