Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ut-sally!husc6!rutgers!ames!lll-tis!ptsfa!hoptoad!academ!uhnix1!sugar!peter From: peter@sugar.UUCP (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: Does ANSI C have lengthof() ? Message-ID: <662@sugar.UUCP> Date: Sun, 6-Sep-87 09:05:05 EDT Article-I.D.: sugar.662 Posted: Sun Sep 6 09:05:05 1987 Date-Received: Wed, 9-Sep-87 05:45:31 EDT References: <9154@brl-adm.ARPA> <1265@mhres.mh.nl> Organization: Sugar Land UNIX - Houston, TX Lines: 37 > I think there is more need for these functions in the pre-processor: > > # if sizeof (char*) == sizeof (int) > typedef int numptr; > # else > # if sizeof (char*) == sizeof (long) > typedef long numptr; > # endif > # endif > # if unknown (typeof (numptr)) > .... error .... > # endif Well, first of all the preprocessor doesn't know the first thing about typedef, other than it's a character string it's copying and ignoring. The preprocessor doesn't know a type from a keyword. It probably doesn't know from sizeof, either... it only knows about constants that have been defined to it with #define. Even if it knows sizeof(int), it shouldn't know about (for example) sizeof(numptr) or sizeof(struct foo). Secondly: # if sizeof (char*) == sizeof (int) # define NUMPTR int # else # if sizeof (char*) == sizeof (long) # define NUMPTR long # endif # endif # if !defined(NUMPTR) .... error .... # endif Finally, I do think typeof would be a great addition to the language. -- -- Peter da Silva `-_-' ...!seismo!soma!uhnix1!sugar!peter -- 'U` <-- Public domain wolf.