* Put_Line for chars_ptr
@ 2002-06-22 23:11 Adrian Knoth
2002-06-23 2:13 ` tmoran
2002-06-23 11:57 ` Sergey Koshcheyev
0 siblings, 2 replies; 5+ messages in thread
From: Adrian Knoth @ 2002-06-22 23:11 UTC (permalink / raw)
Hi!
I have a record (struct) for interfacing uname(). The record looks like
type myStruct is record
sysname : chars_ptr;
nodename: chars_ptr;
release : chars_ptr;
version : chars_ptr;
machine : chars_ptr;
end record;
I guess Pragma Import works well, but if I try to output the content
via Value(varname.sysname) & ... &... it cannot handle a null-pointer
(raise Dereference-Error).
Is this the wrong approach?
--
mail: adi@thur.de http://adi.thur.de PGP: v2-key via keyserver
Jeder redet vom �ffentlichen Verkehr, aber keiner traut sich!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Put_Line for chars_ptr
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
2002-06-23 11:57 ` Sergey Koshcheyev
1 sibling, 1 reply; 5+ messages in thread
From: tmoran @ 2002-06-23 2:13 UTC (permalink / raw)
> via Value(varname.sysname) & ... &... it cannot handle a null-pointer
> (raise Dereference-Error).
What else should Value(null pointer) do? 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;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Put_Line for chars_ptr
2002-06-23 2:13 ` tmoran
@ 2002-06-23 9:20 ` Adrian Knoth
0 siblings, 0 replies; 5+ messages in thread
From: Adrian Knoth @ 2002-06-23 9:20 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Put_Line for chars_ptr
2002-06-22 23:11 Put_Line for chars_ptr Adrian Knoth
2002-06-23 2:13 ` tmoran
@ 2002-06-23 11:57 ` Sergey Koshcheyev
2002-06-23 13:09 ` Adrian Knoth
1 sibling, 1 reply; 5+ messages in thread
From: Sergey Koshcheyev @ 2002-06-23 11:57 UTC (permalink / raw)
"Adrian Knoth" <adi@drcomp.erfurt.thur.de> wrote in message
news:slrnaha10h.102.adi@drcomp.erfurt.thur.de...
> Hi!
>
> I have a record (struct) for interfacing uname(). The record looks like
>
> type myStruct is record
> sysname : chars_ptr;
> nodename: chars_ptr;
> release : chars_ptr;
> version : chars_ptr;
> machine : chars_ptr;
> end record;
I've just looked at the uname man page, and the structure looks like this:
struct utsname {
char sysname[SYS_NMLN];
char nodename[SYS_NMLN];
char release[SYS_NMLN];
char version[SYS_NMLN];
char machine[SYS_NMLN];
char domainname[SYS_NMLN];
};
There aren't pointers there, but the arrays themselves. So you should
declare your Ada structure as
type utsname is record
sysname : char_array (1 .. SYS_NMLN);
...
end record;
Sergey.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Put_Line for chars_ptr
2002-06-23 11:57 ` Sergey Koshcheyev
@ 2002-06-23 13:09 ` Adrian Knoth
0 siblings, 0 replies; 5+ messages in thread
From: Adrian Knoth @ 2002-06-23 13:09 UTC (permalink / raw)
Sergey Koshcheyev <serko84@hotmail.com> wrote:
>> I have a record (struct) for interfacing uname(). The record looks like
>> type myStruct is record
>> sysname : chars_ptr;
> I've just looked at the uname man page, and the structure looks like this:
> struct utsname {
> char sysname[SYS_NMLN];
Oh, thanks a lot. My info-page seems to be wrong on this, they call it
an unbounded char-array, that's why I thought they provide a pointer to
the first character and do the usual stuff like null-terminated strings.
> sysname : char_array (1 .. SYS_NMLN);
It works fine now, thanks.
--
mail: adi@thur.de http://adi.thur.de PGP: v2-key via keyserver
Macht der PC was er will, liegts an Bill!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-06-23 13:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2002-06-23 11:57 ` Sergey Koshcheyev
2002-06-23 13:09 ` Adrian Knoth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox