Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utcsri!greg From: greg@utcsri.UUCP Newsgroups: comp.lang.c Subject: Re: typeof(), like sizeof() (Was: Question on structures) Message-ID: <5667@utcsri.UUCP> Date: Sun, 15-Nov-87 20:33:33 EST Article-I.D.: utcsri.5667 Posted: Sun Nov 15 20:33:33 1987 Date-Received: Tue, 17-Nov-87 02:57:28 EST References: <1025@phoenix.Princeton.EDU> <3022@bunker.UUCP> <150@fxgrp.UUCP> <3025@bobkat.UUCP> <1827@chinet.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 49 Keywords: life, macros, and everything and the inverse thereof. Summary: In article <1827@chinet.UUCP> dag@chinet.UUCP (Daniel A. Glasser) writes: >Though the typeof(thing) facility which is being described in the above >article might be nice, it could not be a part of the preprocessor pass. True. >So the typeof operator (if you don't already know, sizeof is an operator >and only requires the "()"s for grouping.) would be a language extension, >not a preprocessor extension. This operator might be useful, but does not >fit anywhere in the current language definition. The semantics would >have to be similar to declaration of identifiers, but in > > int foo; > >"int" is not an operator. Maybe it could be restricted to typecast >semantics, but this would reduce its usefulness. > How about this: *type-specifier*: char short ... typeof ( *expression* ) << add this ( parens probably essential for parsibility ) typeof ( *type-name* ) << and this *type-name*: << one of many productions missing from K&R *type-specifier* *abstract-declarator* (type-name is anything you can put in parens to get a cast, or give to sizeof as a type). I would say it fits in pretty cleanly. The second case "typeof( *type-name* )" seems a little redundant, but it allows this: typeof( int *(*)()) x,y,z; instead of int *(*x)(), *(*y)(), *(*z)(); or typedef int *(*pfpi)(); pfpi x,y,z; Which might be very handy for certain preprocessers producing C output. #define new(ptr) ((ptr) = (typeof (ptr))malloc( sizeof( *(ptr) ))) -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...