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,d05f012b759bd43a,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 08 Jun 2006 23:45:48 +0200 From: Gautier User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Problem with a C string to Ada conversion Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 83.77.236.38 X-Original-NNTP-Posting-Host: 83.77.236.38 Message-ID: <44889ac7$1_5@news.bluewin.ch> X-Trace: news.bluewin.ch 1149803207 83.77.236.38 (8 Jun 2006 23:46:47 +0200) Organization: Bluewin AG Complaints-To: abuse@bluewin.ch X-Original-NNTP-Posting-Host: 127.0.0.1 Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!news.ip-plus.net!newsfeed.ip-plus.net!news.bluewin.ch!not-for-mail Xref: g2news2.google.com comp.lang.ada:4716 Date: 2006-06-08T23:45:48+02:00 List-Id: Hi. I'm trying to convert a C string to an Ada one and I don't see what's wrong with my code (also tried the variant commented out)... with GL; with Interfaces.C.Strings; with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; procedure Get_GL_Info is use GL; function GetString (name: StringEnm) return String is function Cvt is new Ada.Unchecked_Conversion(ubytePtr,Interfaces.C.Strings.chars_ptr); ps: constant ubytePtr:= GL.GetString(name); --ca: Interfaces.C.char_array:= Interfaces.C.Strings.Value(Cvt(ps)); begin return Interfaces.C.Strings.Value(Cvt(ps)); --return Interfaces.C.To_Ada(ca); end GetString; begin for i in GL.StringEnm loop Put_Line(GL.StringEnm'Image(i) & ": [" & GetString(i) & ']'); end loop; end Get_GL_Info; Here is what happens with this code: The .exe built by GNAT 3.15p / Windows enters seemingly a memory munching race ending by a crash; the one built by ObjectAda 7.2.2 says immediately: Program terminated by an exception propagated out of the main subprogram. Exception raised : INTERFACES.C.STRINGS.DEREFERENCE_ERROR Executable name: GET_GL_INFO.EXE Line Subprogram name File -------- ------------------------------ ------------ 181 interfaces.c.strings.strlen interfaces.c.strings.bdy 253 interfaces.c.strings.value interfaces.c.strings.bdy 297 interfaces.c.strings.value__3 interfaces.c.strings.bdy 15 get_gl_info.getstring get_gl_info.adb 21 get_gl_info get_gl_info.adb 320 _rtsadamain init.c End of propagation. Program aborted. Any clue ? TIA! Gautier _______________________________________________________________ Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site!