Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!samsung!rex!ames!excelan!crdgw1!sixhub!davidsen From: davidsen@sixhub.UUCP (Wm E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Message-ID: <405@sixhub.UUCP> Date: 16 Jan 90 01:48:51 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> <5263@buengc.BU.EDU> Reply-To: davidsen@sixhub.UUCP (bill davidsen) Organization: *IX Public Access UNIX, Schenectady NY Lines: 29 In article <5263@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: | >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... That's not what it's for. You have avoided a possible error caused by changing the type of the items to be swapped. By forcing the temp to be the same type as the items you avoid a type conversion, which could be (a) slow and (b) might generate a roundoff or data loss error. Now my question (no gcc docs on this machine) is, does this return a numeric value? In other words, can I improve my error checking in the macro by saying something like: #define SWAP(a,b) {typeof a tmp;\ assert(typeof a == typeof b);\ tmp = a; a = b; b = tmp; } All this requires is that the evaluation return a discrete value for all types, but the user defined types would be a problem. I can envision a PRINT macro which would use typeof to select the format of the print. I can envision it, and it's UGLY... -- bill davidsen - sysop *IX BBS and Public Access UNIX davidsen@sixhub.uucp ...!uunet!crdgw1!sixhub!davidsen "Getting old is bad, but it beats the hell out of the alternative" -anon