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,7b65fc33a05f24b6 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!w34g2000yqm.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: A curiosity... Date: Thu, 4 Dec 2008 14:04:28 -0800 (PST) Organization: http://groups.google.com Message-ID: <0f009ce8-0f50-4b85-9368-0d0c68f42da1@w34g2000yqm.googlegroups.com> References: NNTP-Posting-Host: 94.108.135.128 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1228428268 30580 127.0.0.1 (4 Dec 2008 22:04:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 4 Dec 2008 22:04:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w34g2000yqm.googlegroups.com; posting-host=94.108.135.128; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.17) Gecko/20080829 Iceape/1.1.12 (Debian-1.1.12-1),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:3847 Date: 2008-12-04T14:04:28-08:00 List-Id: On Dec 4, 10:48 pm, Hyman Rosen wrote: > Adam Beneschan wrote: > > Ahhh, sanity at last... > > In fact, that "chilling" code wasn't really bad. It's just that > pthread_create gets a void * final parameter which it passes along > as an argument to the thread function it starts. The tutorial code > wants to pass in a plain integer, so it casts the integer into a > pointer so that it can pass it to pthread_create and then the thread > routine casts it back to an integer. > > On any conventional architecture, casting a small integer to pointer > and back will leave its value unchanged, and the ability to do this > very common in C compilers and has been for decades. Yes. In fact, C requires that pointers and integers be interchangable so as to make address arithmetic "transparent" and extremely dangerous. That's why, instead of writing "&th[t]" as Adam did, they wrote "th+t" and thought themselves clever. I'm glad I no longer program in C or C++. -- Ludovic Brenta.