Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!neville%zodiac@ads.arpa From: neville%zodiac@ads.arpa (Neville Newman) Newsgroups: comp.lang.c Subject: Re: Does ANSI C have lengthof() ? Message-ID: <9154@brl-adm.ARPA> Date: Thu, 3-Sep-87 15:19:38 EDT Article-I.D.: brl-adm.9154 Posted: Thu Sep 3 15:19:38 1987 Date-Received: Sat, 5-Sep-87 11:17:29 EDT Sender: news@brl-adm.ARPA Lines: 37 #From: Walter Bright # #In article <761@cg-atla.UUCP> mallett@cg-atla.UUCP (Bruce Mallett) writes: # # I always define a macro "lengthof()" in my standard header file to # #return the length of an array. The definition looks something like: # # #define lengthof(x) ( sizeof(x)/sizeof(x[0]) ) # #This is the kind of thing that would be better built into the compiler # #much as is sizeof(). # #I would rather it not be built into the compiler, as it is such an easy #macro (I use the same macro myself). One thing I want, which the committee #always seems to poo-poo, is a typeof. Having a typeof would make #creation of 'generic' routines possible: # # #define swap(a,b) { typeof(a) tmp; tmp = a; a = b; b = tmp; } # #A typeof capability is rather trivial to implement in the compile itself #(at least it is on my compiler!). # i wholeheartedly agree - lengthof() is such an easy macro it need not be implemented in the compiler, and typeof() is a very useful pseudo-function to have in the compiler. i implemented typeof() in pcc a couple of years ago, it was quite simple. Sorry, but i don't have the diffs. -neville ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ U.S. Mail: Neville D. Newman Advanced Decision Systems 201 San Antonio Circle, Suite 286 Mountain View, CA 94040-1289 Phone: (415) 941-3912 Net mail: neville@ads.arpa (internet-relative)