Related articles |
---|
Does Duff Device break C compilers Lambert.Lum@eng.efi.com (Lambert Lum) (1996-05-06) |
Re: Does Duff Device break C compilers preston@tera.com (1996-05-07) |
Re: Does Duff Device break C compilers krste@ICSI.Berkeley.EDU (1996-05-08) |
Re: Does Duff Device break C compilers jeremy@floyd.sw.oz.au (1996-05-10) |
Re: Does Duff Device break C compilers rankin@eql.caltech.edu (1996-05-10) |
Re: Does Duff Device break C compilers msb@sq.com (1996-05-10) |
Re: Does Duff Device break C compilers preston@tera.com (1996-05-13) |
Re: Does Duff Device break C compilers baynes@ukpsshp1.serigate.philips.nl (1996-05-19) |
From: | preston@tera.com (Preston Briggs) |
Newsgroups: | comp.compilers |
Date: | 13 May 1996 14:17:59 -0400 |
Organization: | /etc/organization |
References: | 96-05-054 96-05-057 96-05-071 |
Keywords: | C, optimize |
>: Better is to rewrite it, like this
>: /* no assumptions made about count */
>: for (n = 0; n < count; n++)
>: to[n] = from[n];
>: which is correct, obvious, maintainable, parallelizable, vectorizable,
>> Better yet, "Krste's Kopy" :-)
>> memcpy(from, to, count*(sizeof *from));
> I wouldn't ordinarily comment on something like this, but I find
>it highly ironic that both of these "obviously correct improvements"
>fail to reimplement the original code, and produce entirely different
>results.
Sorry, this was all my fault. However, it wasn't a misteak (besides
the usual mistake of posting). I read the original code and thought
to my self: "This is stupid. Why didn't he write
*to = from[count -1];
with no loop at all? Oh, he must have left out the ++ when he typed
it in." Hence my trite little comment that my version was "obviously
correct".
As about 75,000 people pointed out, Duff's original code assumed that
*to is a device register (not that the assumption was mentioned
anywhere in the posted code).
Preston Briggs
(All spelling errors added purposely.)
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.