Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Summary: Sold. GNU C has it, and it's great. But not ANSI :-( Message-ID: <676@s5.Morgan.COM> Date: 13 Jan 90 22:44:53 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> Organization: Morgan Stanley & Co. NY, NY Lines: 30 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. > Damn right it's useful. You can write concurrent assignment in general using ANSI standard C without this trick, but you need to go through a lot of alignment pain and type-defeating function calls to get there. On some systems, you can get it all done for about a two or threefold performance penalty. On the RISC chips, you're totally nailed for a factor on the order of 30 (THIRTY). GNU C (gcc) has this little trick, and the performance penalty evaporates. but you don't even have to use the typeof function (?) (It seems a little bit different than most C functions). You can define a temporary variable for the value in say, a variable x by typedef _type_of_x (x); _type_of_x temp_x = x; Is there a down side to these facilities? (I.e. why didn't people put 'em in ANSI? I'd really like to use GNU C, but it ain't likely to show up in DOS or OS/2 this year, (or is it?)). Later, Andrew Mullhaupt