Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!ut-sally!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.UUCP Newsgroups: net.lang.c Subject: Re: fast code and no morals Message-ID: <1820@brl-tgr.ARPA> Date: Wed, 22-Jan-86 12:21:58 EST Article-I.D.: brl-tgr.1820 Posted: Wed Jan 22 12:21:58 1986 Date-Received: Fri, 24-Jan-86 21:29:12 EST References: <842@megaron.UUCP> Distribution: net Organization: Ballistic Research Lab Lines: 40 > Here's a version of calloc that breaks every rule of "structured" > programming ever invented -- and runs about twice as fast as a > vanilla version: > > /* calloc - allocate and clear memory block */ > #define CHARPERINT (sizeof(int)/sizeof(char)) > #define NULL 0 > > char *calloc(num, size) > unsigned num, size; > { > register char *mp; > char *malloc(); > register int *q, *qlim, m; > > num *= size; > mp = malloc(num); > if (mp == NULL) return (NULL); > q = (int *) mp; > qlim = (m = (num+CHARPERINT-1)/CHARPERINT) + (q = (int *)mp); > > switch (m & 7) > do { > *q++ = 0; > case 7: *q++ = 0; > case 6: *q++ = 0; > case 5: *q++ = 0; > case 4: *q++ = 0; > case 3: *q++ = 0; > case 2: *q++ = 0; > case 1: *q++ = 0; > case 0: ; > } while (q < qlim); > > return (mp); > } So what? This can be written "structured", and would be more maintainable if it were. Surely this is not an example of recommended practice?