comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Using fwrite in Ada
Date: Thu, 11 Aug 2005 14:59:35 -0700
Date: 2005-08-11T14:59:35-07:00	[thread overview]
Message-ID: <dTPKe.6$Vy6.5@dfw-service2.ext.ray.com> (raw)
In-Reply-To: <caGdnZ2dnZ30zOuZnZ2dncEZZt-dnZ2dRVn-y52dnZ0@comcast.com>

tmoran@acm.org wrote:
> 
>> cptr : chars_ptr;
>> Buffer : String (1..100);
>>  cptr:=New_String(Buffer);
> 
>   implies that chars_ptr is an access to an unconstrained array.  So it
> points to both the subscript range of the string and to the character data
> in the string.  That is not the same thing as a C pointer to a byte (that
> may happen to be the first byte in the string).

No. From ARM B.3.1(22): 'The type chars_ptr is C-compatible and 
corresponds to the use of C's ``char *'' for a pointer to the first char 
in a char array terminated by nul.'

> 
>>  vptr:=voids(cptr);
>>
>>  fwrite(vptr,100,1,stdout);
>>But this won't compile, the compiler says that it cannot convert the
>>chars_ptr to voids. Coming from a C background, I don't understand why
>>something cannot be cast to void.
> 
>    In Ada, type matters.  What would you expect to happen if you said
>   cptr := chars_ptr(vptr);
> How would the cptr find out the size of the string that held the byte
> that vptr currently points to?

The problem is that Chars_Ptr is defined as

type chars_ptr is private;

Thus, it is not an access type, so there is no conversion to an access 
type defined for it.

All this is an elephant, however, since there are better ways to do 
binary output to standard output.

-- 
Jeffrey Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
E-mail: jeffrey_r_carter-nr [commercial-at]
         raytheon [period | full stop] com



      reply	other threads:[~2005-08-11 21:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-10 17:01 Using fwrite in Ada Makhno
2005-08-10 17:28 ` Georg Bauhaus
2005-08-10 18:05 ` Martin Krischik
2005-08-11 17:01 ` tmoran
2005-08-11 21:59   ` Jeffrey Carter [this message]
replies disabled

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