From: Adam Beneschan <adam@irvine.com>
Subject: Re: Pascal Calling Convention
Date: Mon, 28 Mar 2011 15:08:50 -0700 (PDT)
Date: 2011-03-28T15:08:50-07:00 [thread overview]
Message-ID: <d68b20bc-3aa5-4cc5-bd8e-a944dee20f24@a11g2000pri.googlegroups.com> (raw)
In-Reply-To: 4d90fd41$1$14782$882e7ee2@usenet-news.net
On Mar 28, 2:26 pm, Hyman Rosen <hyro...@mail.com> wrote:
> On 3/28/2011 5:16 PM, Adam Beneschan wrote:
>
> > I hope your "favorite data structure" comment was sarcastic. I would
> > expect this code to behave incorrectly a large portion of the time;
> > specifically, if I read the code right, once you add any element to
> > the set, the program is likely to think 0 is in the set whether you've
> > added it or not.
>
> I wrote the code from memory so it's possible I made a mistake,
> but I don't think you're correct - you're likely not reading the
> code right.
OK, I've looked at it again and you may be right. However, it's also
not a relevant example; I don't see how any compiler could reasonably
detect that the code is going to read a value that hasn't been set,
given that such reads are reads of array elements using indexes that
aren't known at compile time. Maybe a really clever compiler that
inlines can see (from the code that uses this structure) that the
first operation is "add" which calls "has" which is going to read a
value in the "s" array before anything has been set; on the other
hand, a compiler that's that clever will also figure out that "n" has
to be 0 at that point which means that it can determine s[k] < n will
necessarily be false without having to read from the array at all.
Anyway, I think the sort of code Keith was talking about involved a
single variable that was read when uninitialized---probably was never
set to anything at all in the program---which is much more plausible
for a compiler to treat as an "undefined" operation.
On top of that, I don't see why anyone would prefer this over the
trivial structure that just allocates N bytes, initializes them to 0,
and sets a byte to 1 to add an element to the set, etc. That
structure has non-constant initialization, but so what?
Initialization will only take place once for a set; the other
operations are likely to be performed a lot more, and your code
performs multiple indexed accesses for every operation instead of just
one. And the initialization can often be done with a single machine
instruction.
-- Adam
next prev parent reply other threads:[~2011-03-28 22:08 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-23 21:37 Pascal Calling Convention Shark8
2011-03-23 23:25 ` Yannick Duchêne (Hibou57)
2011-03-24 0:24 ` Randy Brukardt
2011-03-24 0:43 ` Yannick Duchêne (Hibou57)
2011-03-24 2:04 ` Shark8
2011-03-25 15:40 ` Yannick Duchêne (Hibou57)
[not found] ` <F8mdnYCca6tRJBfQnZ2dnUVZ_s-dnZ2d@earthlink.com>
2011-03-24 19:20 ` Keith Thompson
2011-03-25 16:04 ` Robert A Duff
2011-03-25 17:02 ` Hyman Rosen
2011-03-25 17:09 ` Robert A Duff
2011-03-25 17:35 ` Hyman Rosen
2011-03-26 19:51 ` Robert A Duff
2011-03-25 17:51 ` Keith Thompson
2011-03-26 20:46 ` Robert A Duff
2011-03-27 2:24 ` Randy Brukardt
2011-03-28 15:41 ` Adam Beneschan
2011-03-28 19:52 ` Robert A Duff
2011-03-29 2:32 ` Randy Brukardt
2011-03-29 6:06 ` Shark8
2011-03-29 23:45 ` Randy Brukardt
2011-03-29 19:19 ` Robert A Duff
2011-03-30 0:02 ` Randy Brukardt
2011-03-30 12:40 ` Robert A Duff
2011-03-30 19:40 ` Randy Brukardt
2011-03-30 20:56 ` tmoran
2011-03-30 22:34 ` Robert A Duff
2011-03-31 21:00 ` Randy Brukardt
2011-03-28 20:29 ` Hyman Rosen
2011-03-28 21:16 ` Adam Beneschan
2011-03-28 21:26 ` Hyman Rosen
2011-03-28 22:08 ` Adam Beneschan [this message]
2011-03-28 23:47 ` Georg Bauhaus
2011-03-29 12:23 ` stefan-lucks
2011-03-29 13:10 ` Hyman Rosen
2011-03-30 13:42 ` Phil Clayton
2011-03-31 7:40 ` Phil Clayton
2011-03-29 2:48 ` Hyman Rosen
2011-03-29 18:30 ` Robert A Duff
2011-03-29 23:25 ` Adam Beneschan
2011-03-30 12:50 ` Robert A Duff
2011-03-30 14:47 ` Adam Beneschan
2011-03-30 18:10 ` Robert A Duff
2011-03-29 3:01 ` Hyman Rosen
2011-03-29 18:22 ` Robert A Duff
2011-03-26 21:30 ` Florian Weimer
2011-03-27 16:18 ` Robert A Duff
2011-03-27 16:38 ` Florian Weimer
2011-03-27 16:56 ` Robert A Duff
2011-03-24 2:15 ` Shark8
2011-03-24 0:38 ` ytomino
2011-03-24 2:23 ` Shark8
2011-03-24 21:29 ` Gautier write-only
2011-03-25 12:47 ` Marco
2011-03-25 15:38 ` Yannick Duchêne (Hibou57)
2011-03-26 8:39 ` ObjectAda [was: Pascal Calling Convention] Gautier write-only
2011-03-26 14:05 ` Marco
2011-03-26 21:58 ` Gautier write-only
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox