Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!rutgers!texbell!swbatl!uucibg From: uucibg@swbatl.UUCP (3929) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Message-ID: <1109@swbatl.UUCP> Date: 16 Jan 90 03:48:16 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> Reply-To: uucibg@swbatl.UUCP (Brian Gilstrap - UCI - 5-3929) Organization: Southwestern Bell Tele. Co. - Advanced Technology Lab - St. Louis Lines: 48 In article <-K016ODxds13@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: >> 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: > > struct { > union uabc { > struct { > int a; > int b; > } ab; > long c; > } abc; > union uabc *d; > struct stat buf; > } x; > >But a typeof operator... wouldn't that be something... > >#define SWAP(a,b) {typeof a tmp; tmp=a; a=b; b=tmp} :-). Implementing this is, of course, a rather complex task. Certainly doable, since this provides at least as much expressive power as operator overloading in C++. But by no means is it as easy to implement as sizeof. >Peter da Silva. +1 713 274 5180. . But it sure would be nice... -------------------------------------------------------------------------------- Brian R. Gilstrap ...!{ texbell, uunet }!swbatl!uucibg OR uucibg@swbatl.UUCP One Bell Center +---------------------------------------------------------- Rm 17-G-4 | "Winnie-the-Pooh read the two notices very carefully, St. Louis, MO 63101 | first from left to right, and afterwards, in case he had (314) 235-3929 | missed some of it, from right to left." -- A. A. Milne -------------------------------------------------------------------------------- Disclaimer: Me, speak for my company? You must be joking. I'm just speaking my mind.