comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Subject: Re: Put_Line for chars_ptr
Date: 23 Jun 2002 09:20:06 GMT
Date: 2002-06-23T09:20:06+00:00	[thread overview]
Message-ID: <slrnahb4m6.e4h.adi@drcomp.erfurt.thur.de> (raw)
In-Reply-To: a9aR8.56$U67.17749105@newssvr13.news.prodigy.com

tmoran@acm.org <tmoran@acm.org> wrote:

>> via Value(varname.sysname) & ... &... it cannot handle a null-pointer
>> (raise Dereference-Error).
>   What else should Value(null pointer) do?  

But there is no null pointer. It only complains about it, the record is
filled out.

> How about using something like:
> function S(Item : in chars_ptr) return String is
> begin
>   if Item = Null_Ptr then return "?";
>   else return Value(Item);
> end S;

This is exactly the code Interfaces.C.Strings uses:

   function Value (Item : in chars_ptr) return char_array is
      Result : char_array (0 .. Strlen (Item));

   begin
      if Item = Null_Ptr then
         raise Dereference_Error;
      end if;

      --  Note that the following loop will also copy the terminating Nul

      for J in Result'Range loop
         Result (J) := Peek (Item + J);
      end loop;

      return Result;
   end Value;

(it first generates char_array from chars_ptr and then converts this array
via To_Ada to an ordinary string:

   function Value (Item : in chars_ptr) return String is
   begin
      return To_Ada (Value (Item));
   end Value;

I think this is what I want to do, but it fails. Sometimes with storage_error.

-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Never underestimate the power of a small tactical nuclear weapon.



  reply	other threads:[~2002-06-23  9:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-22 23:11 Put_Line for chars_ptr Adrian Knoth
2002-06-23  2:13 ` tmoran
2002-06-23  9:20   ` Adrian Knoth [this message]
2002-06-23 11:57 ` Sergey Koshcheyev
2002-06-23 13:09   ` Adrian Knoth
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox