Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!mephisto!eedsp!baud From: baud@eedsp.eedsp.gatech.edu (Kurt Baudendistel) Newsgroups: comp.lang.c Subject: Re: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Message-ID: <721@eedsp.eedsp.gatech.edu> Date: 15 Jan 90 22:54:29 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> Reply-To: baud@eedsp.UUCP (Kurt Baudendistel) Organization: Georgia Institute of Technology Lines: 39 GCC, the GNU C compiler, implements the ``typeof'' operator as it is being discussed here. It allows an argument that can be an expression (an r-value) or a type. The ``typeof'' construct can be used anywhere a typedef name could be used (in any declaration or definition). Be careful, however, of the nasty C preprocessor, which will make this nice looking and appealing definition: #define SWAP(a,b) {typeof (a) tmp; tmp=a; a=b; b=tmp} [courtesy of peter@ficc.uu.net (Peter da Silva)] fail in many cases, like if (x < y) SWAP (x, y); // bracketing of SWAP makes the `;' extraneous else // and fatal x = y; or int tmp; ... SWAP (x, tmp); // name ``tmp'' in SWAP makes this fail or int a[10], b[10]; ... SWAP (a, b); // will this work? // depends on your definition of `=' can you think of other pitfalls? kurt -- Kurt Baudendistel --- GRA Georgia Tech, School of Electrical Engineering, Atlanta, GA 30332 internet: baud@eedsp.gatech.edu uucp: gatech!gt-eedsp!baud