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,74bc23dcb20218db X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news4.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.78.MISMATCH!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: How to access this package written in C? Date: Mon, 26 Apr 2010 12:57:17 -0700 Organization: None to speak of Message-ID: References: <4e9d2aaf-c0a6-4798-b838-8f5b7c4a39d1@k33g2000yqc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 26 Apr 2010 19:57:26 +0000 (UTC) Injection-Info: news.eternal-september.org; posting-host="9nFTuw1iclElqUG5+//YDQ"; logging-data="29790"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3+W4Dx9P3BIDUKvFwrw1T" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:HXpC1/vU3iM5Bt5E9NrPUgGv5ic= sha1:D3x3/05VjBG6XfaLKU9QtPzI+s0= Xref: g2news1.google.com comp.lang.ada:10219 Date: 2010-04-26T12:57:17-07:00 List-Id: Robert A Duff writes: > resander writes: > >> On Apr 22, 10:12 pm, Keith Thompson wrote: >>> There is no guarantee that an int can hold the value of an address, >>> and there are common systems (including Linux systems) where it >>> can't.  Worse, you're not likely to get a warning if you convert >>> a pointer to int, even if there's a loss of information. > > Why? I'd think if int is smaller than whatever*, then > a cast to int clearly deserves a warning. I made an assumption, thereby making an ass out of me and umption. In fact gcc does warn about converting a pointer to a smaller integer type: warning: cast from pointer to integer of different size As the wording implies, it produces the same warning for a cast from a pointer to a larger integer type. I haven't checked other C compilers. In many cases, though, C compilers tend to take a cast operator to mean "do this conversion and don't bother me, I know what I'm doing". [...] >> Thank you all for your concerns about using an int for passing an >> address. The interface actually uses a void * (could also be char * as >> that is what is needed), but I changed it for the post because I >> thought an all-int interface would be easier to handle at the Ada-to-C >> boundary. That seems to have backfired! > > You should look at section B (especially B.3) of the Ada RM. > There's a type char_star you can use. > > There's no void_star. I'm not sure why -- probably this > part of Ada predates void* in C, and nobody bothered > to upgrade Ada to match the new C. As I recall, Ada 83 didn't have any of this; it was introduced in Ada 95. void* was introduced in the ANSI C standard in 1989 (reissued with cosmetic changes as the ISO C standard in 1990). But C still requires char* and void* to have the same representation. But in the Ada RM, I only see char_star in an example: subtype Char_Star is Char_Ptrs.Pointer; [snip] The document I'm looking at is "Ada Reference Manual, ISO/IEC 8652:2007(E) Ed. 3", "ISO/IEC 8652:1995(E) with Technical Corrigendum 1 and Amendment 1". Is that the most current version? A few comments on Interfaces.C: plain_char is a subtype of either unsigned_char or signed_char. In C, plain char is actually a distinct type, though it has the same representation as either unsigned char or signed char. It would be more consistent to have either type plain_char is new signed_char; or type plain_char is new unsigned_char; depending on the implementation. There's no need for nul, wide_nul, and char32_nul to be implementation-defined; they're all zero by definition: nul : constant char := char'val(0); ... wide_nul : constant wchar_t := wchar_t'val(0); ... char32_nul : constant char32_t := char32_t'val(0); C doesn't actually have a type corresponding to char32_t; it has wchar_t, but its size is implementation-defined. Execution of Free(X) is also erroneous if the chars_ptr X was not returned by New_Char_Array or New_String. It should also be mentioned that calling Free twice on the same pointer value is erroneous (you can do this by saving a copy of the pointer before the first call to Free). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"