Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!chinet!dag From: dag@chinet.UUCP Newsgroups: comp.lang.c Subject: Re: typeof(), like sizeof() (Was: Question on structures) Message-ID: <1827@chinet.UUCP> Date: Tue, 10-Nov-87 11:06:52 EST Article-I.D.: chinet.1827 Posted: Tue Nov 10 11:06:52 1987 Date-Received: Sat, 14-Nov-87 11:58:42 EST References: <1025@phoenix.Princeton.EDU> <3022@bunker.UUCP> <150@fxgrp.UUCP> <3025@bobkat.UUCP> Reply-To: dag@chinet.UUCP (Daniel A. Glasser) Organization: Chinet - Public Access Unix Lines: 50 Keywords: life, macros, and everything and the inverse thereof. Summary: typeof could not be a preprocessor function In article <3025@bobkat.UUCP> m5@bobkat.UUCP (Mike McNally (Man from Mars)) writes: > [ lots of stuff deleted ] >On a related but completely different topic: does anybody else think that >a "typeof(thing)" would be useful? Seems like it would make a lot of macros >easier and cleaner. What are the philosophical issues behind extending >(or the reluctance to extend) the preprocessor? Would more powerful macro >capabilities actually introduce a new world of obscurity to the language? > [ more stuff deleted ] >-- >Mike McNally, mercifully employed at Digital Lynx --- > [ Signiture deleted ] 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. A compiler that combines parsing with preprocessing in one pass might get away with it, but the preprocessor, as defined, knows nothing about the C language other than preprocessor things (like comments). It does not know what variables are declared, what types are defined, or even what types are. C programmers who have never worked with languages with built-in macro facilities (C has a preprocessor, which is different) don't seem to realize that the macro facilities available to the C programmer through the preprocessor are minimal. There is no real macro capability in the C language itself. The C preprocessor does not know the structure of a program or of the C language. A particular implimentation might, but that is not portable. (For a good example of a "High Level" language with a really powerful macro facilities (not a preprocessor), take a look at BLISS.) 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. -- Daniel A. Glasser ----------------------------------------+---------------------------- Cheese is not a discipline! | ...!ihnp4!chinet!dag | ...!ihnp4!mwc!gorgon!dag | ...!ihnp4!chinet!gorgon!dag Disclaimer: I assume full responsibility for my opinions. If my employer knew of some of them, I'd be unemployed.