From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2cb1f0b6d642e1dc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a11g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Pascal Calling Convention Date: Mon, 28 Mar 2011 15:08:50 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9b04626e-567d-408c-aab3-39b964b3ffd6@l2g2000prg.googlegroups.com> <4d90efdd$1$14806$882e7ee2@usenet-news.net> <330393be-cb82-4cd8-ba44-6e59af7b75bf@v11g2000prb.googlegroups.com> <4d90fd41$1$14782$882e7ee2@usenet-news.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1301350130 15271 127.0.0.1 (28 Mar 2011 22:08:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 28 Mar 2011 22:08:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a11g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19528 Date: 2011-03-28T15:08:50-07:00 List-Id: On Mar 28, 2:26=A0pm, Hyman Rosen wrote: > On 3/28/2011 5:16 PM, Adam Beneschan wrote: > > > I hope your "favorite data structure" comment was sarcastic. =A0I 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