comp.lang.ada
 help / color / mirror / Atom feed
* Unbounded_String'Write et al in GNAT
@ 2017-11-13 22:09 Victor Porton
  2017-11-13 22:15 ` Victor Porton
  2017-11-14 15:05 ` Simon Wright
  0 siblings, 2 replies; 4+ messages in thread
From: Victor Porton @ 2017-11-13 22:09 UTC (permalink / raw)


GNAT has 

   for Unbounded_String'Write  use Unbounded_String_Write;
   for Unbounded_String'Read   use Unbounded_String_Read;
   for Unbounded_String'Output use Unbounded_String_Write;
   for Unbounded_String'Input  use Unbounded_String_Input;

in package Ada.Strings.Unbounded.

Ada2012 seems not to provide them.

Is it standard conformant?

Or better, should we add this to the standard?

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unbounded_String'Write et al in GNAT
  2017-11-13 22:09 Unbounded_String'Write et al in GNAT Victor Porton
@ 2017-11-13 22:15 ` Victor Porton
  2017-11-14 15:05 ` Simon Wright
  1 sibling, 0 replies; 4+ messages in thread
From: Victor Porton @ 2017-11-13 22:15 UTC (permalink / raw)


Victor Porton wrote:

> GNAT has
> 
>    for Unbounded_String'Write  use Unbounded_String_Write;
>    for Unbounded_String'Read   use Unbounded_String_Read;
>    for Unbounded_String'Output use Unbounded_String_Write;
>    for Unbounded_String'Input  use Unbounded_String_Input;
> 
> in package Ada.Strings.Unbounded.

(private part).

> Ada2012 seems not to provide them.
> 
> Is it standard conformant?
> 
> Or better, should we add this to the standard?
> 
-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unbounded_String'Write et al in GNAT
  2017-11-13 22:09 Unbounded_String'Write et al in GNAT Victor Porton
  2017-11-13 22:15 ` Victor Porton
@ 2017-11-14 15:05 ` Simon Wright
  2017-11-15 22:34   ` Randy Brukardt
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Wright @ 2017-11-14 15:05 UTC (permalink / raw)


Victor Porton <porton@narod.ru> writes:

> GNAT has 
>
>    for Unbounded_String'Write  use Unbounded_String_Write;
>    for Unbounded_String'Read   use Unbounded_String_Read;
>    for Unbounded_String'Output use Unbounded_String_Write;
>    for Unbounded_String'Input  use Unbounded_String_Input;
>
> in package Ada.Strings.Unbounded.
>
> Ada2012 seems not to provide them.
>
> Is it standard conformant?
>
> Or better, should we add this to the standard?

No.

ARM 13.13.2(2)ff [1] says

For every subtype S of a specific type T, the following attributes are
defined. 

S'Write
S'Write denotes a procedure with the following specification: 
procedure S'Write(
   Stream : not null access Ada.Streams.Root_Stream_Type'Class;
   Item : in T)
S'Write writes the value of Item to Stream.

S'Read
S'Read denotes a procedure with the following specification: 
procedure S'Read(
   Stream : not null access Ada.Streams.Root_Stream_Type'Class;
   Item : out T)
S'Read reads the value of Item from Stream.

And (18) says much the same about 'Output, 'Input.

So Unbounded_String _must_ support 'Read, 'Write, 'Output, 'Input, but
it's up to the compiler vendor to implement them, which GNAT does *in*
*the* *private* *part* - which is exactly the way the standard expects
any other vendor to do it. The ARG goes to a lot of trouble to ensure
that a vendor can implement the standard's requirements.

[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-13-13-2.html#p2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unbounded_String'Write et al in GNAT
  2017-11-14 15:05 ` Simon Wright
@ 2017-11-15 22:34   ` Randy Brukardt
  0 siblings, 0 replies; 4+ messages in thread
From: Randy Brukardt @ 2017-11-15 22:34 UTC (permalink / raw)


"Simon Wright" <simon@pushface.org> wrote in message 
news:lyzi7oew9c.fsf@pushface.org...
> Victor Porton <porton@narod.ru> writes:
...
> So Unbounded_String _must_ support 'Read, 'Write, 'Output, 'Input, but
> it's up to the compiler vendor to implement them, which GNAT does *in*
> *the* *private* *part* - which is exactly the way the standard expects
> any other vendor to do it. The ARG goes to a lot of trouble to ensure
> that a vendor can implement the standard's requirements.
>
> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-13-13-2.html#p2

Correct. All non-limited types defined in the Standard or by 
language-defined declarations have to properly support 'Read, 'Write and the 
rest. How that happens is up to the implementation.

It might be the case that some compiler can implement Unbounded_String'Read 
and so on without any explicit code (that is, the default implementation 
does the right thing), in which case no additional code is necessary. Based 
on your message, GNAT needs to override the default implementation for 
Unbounded_String and thus does so in the private part. That's exactly the 
way it ought to work.

In general, looking at a particular implementation's source code for a 
language-defined package can give one the wrong idea about the 
implementation. One should depend only on the RM definition and its 
requirements as much as possible, as that maximizes portability.

                                      Randy.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-15 22:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 22:09 Unbounded_String'Write et al in GNAT Victor Porton
2017-11-13 22:15 ` Victor Porton
2017-11-14 15:05 ` Simon Wright
2017-11-15 22:34   ` Randy Brukardt

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