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,97d5e85b59d5e24c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Mon, 23 Aug 2004 22:31:13 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <3f27506b.0408200022.76094a5e@posting.google.com> Subject: Re: Ada equivalent to С++ header sentence. Date: Mon, 23 Aug 2004 22:32:09 -0500 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-Gwku/QuJICZQbtl8MG2JkmW4NLZSJ8m80Wj5g8zbsG2/B6+9ohEdJxhinEom54ExyNgJh55KnRzOL3N!aSd1ZA7CiUOrIRp+w9zPX9fhLoS4bPEgxleuwqMQpIq71UiO9ckxHaAviXPnRJEZiCUQJ6bYk8CD X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.13 Xref: g2news1.google.com comp.lang.ada:2948 Date: 2004-08-23T22:32:09-05:00 List-Id: "Stephen Leake" wrote in message news:mailman.5.1093005464.28011.comp.lang.ada@ada-france.org... > rhezusfactor@yahoo.com (Johnswort) writes: ... > > Presumingly, LPSTR may come from Win32. > > Yes, it stands for "Long Pointer to String". You might be tempted to > define it in Ada as: > > type LPSTR is access String; -- WRONG! > > But since an Ada string is an Ada array, and a C string is just a > pointer to Char, this is wrong. You can use Interfaces.C.Pointers, but > that gets very cumbersome. Use System.Address, and make sure you > append ASCII.Nul to the end of any strings passed to C. I was with you until this point, but I don't agree with the advice to use System.Address. Using it in Ada 95 (other than with an address clause) represents a design mistake in my view. Claw defines LPStr as type LPStr is access all Interfaces.C.Char; and uses the Interfaces.C To_C and To_Ada functions to do the needed conversions. Note that Interfaces.C.Char_Array has aliased components, so that Name(Name'First)'Access passes the first character of a Char_Array, (and thus the whole array in C terms). This has the advantage of being more strongly typed - it's still possible to pass a char array that's not null terminated, but you can't accidentially pass an array of integers or (more commonly) some record type. Rule of thumb: Never, ever write weakly typed code when it's reasonable to write strongly typed code. An alternative is to use Interfaces.C.Strings (there's no reason to mess with Interfaces.C.Pointers for this), but it tends to make you do some storage management that's usually unnecessary. (We also didn't have it working in Janus/Ada when we started Claw, which is probably really why we avoided it.) Randy.