comp.lang.ada
 help / color / mirror / Atom feed
* ambiguous expression (cannot resolve "Put")
@ 2019-07-27  7:32 cryintothebluesky
  2019-07-27  8:28 ` J-P. Rosen
  0 siblings, 1 reply; 3+ messages in thread
From: cryintothebluesky @ 2019-07-27  7:32 UTC (permalink / raw)


Hi, could anyone suggest how to print 'Size attribute for various integers? There seems to be an issue with overloaded Put() function. Not sure why only 'Size attribute causes this issue, other attributes like 'First and 'Last seem OK. I suppose I could do something like Ada.Integer_Text_IO.Put() and Ada.Short_Integer_Text_IO.Put() but this doesn't look very nice. 


with Ada.Text_IO;               use Ada.Text_IO;
with Ada.Integer_Text_IO;       use Ada.Integer_Text_IO;
with Ada.Short_Integer_Text_IO; use Ada.Short_Integer_Text_IO;

procedure Integer_Types is
begin
	Put("Integer'Size        "); Put(Integer'Size); New_Line;
	Put("Integer'First       "); Put(Integer'First); New_Line;
	Put("Integer'Last        "); Put(Integer'Last); New_Line;

	Put("Short_Integer'Size  "); Put(Short_Integer'Size); New_Line;
	Put("Short_Integer'First "); Put(Short_Integer'First); New_Line;
	Put("Short_Integer'Last  "); Put(Short_Integer'Last); New_Line;
end Integer_Types;


Compile
   [Ada]          integer_types.adb
integer_types.adb:13:38: ambiguous expression (cannot resolve "Put")
integer_types.adb:13:38: possible interpretation at a-tiinio.ads:66, instance at a-siteio.ads:18
integer_types.adb:13:38: possible interpretation at a-tiinio.ads:66, instance at a-inteio.ads:18
integer_types.adb:17:38: ambiguous expression (cannot resolve "Put")
integer_types.adb:17:38: possible interpretation at a-tiinio.ads:66, instance at a-siteio.ads:18
integer_types.adb:17:38: possible interpretation at a-tiinio.ads:66, instance at a-inteio.ads:18
gprbuild: *** compilation phase failed

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

* Re: ambiguous expression (cannot resolve "Put")
  2019-07-27  7:32 ambiguous expression (cannot resolve "Put") cryintothebluesky
@ 2019-07-27  8:28 ` J-P. Rosen
  2019-07-27  9:09   ` cryintothebluesky
  0 siblings, 1 reply; 3+ messages in thread
From: J-P. Rosen @ 2019-07-27  8:28 UTC (permalink / raw)


Le 27/07/2019 à 09:32, cryintothebluesky@gmail.com a écrit :
> Hi, could anyone suggest how to print 'Size attribute for various integers? There seems to be an issue with overloaded Put() function. Not sure why only 'Size attribute causes this issue, other attributes like 'First and 'Last seem OK. I suppose I could do something like Ada.Integer_Text_IO.Put() and Ada.Short_Integer_Text_IO.Put() but this doesn't look very nice. 
> 
> 
> with Ada.Text_IO;               use Ada.Text_IO;
> with Ada.Integer_Text_IO;       use Ada.Integer_Text_IO;
> with Ada.Short_Integer_Text_IO; use Ada.Short_Integer_Text_IO;
> 
> procedure Integer_Types is
> begin
> 	Put("Integer'Size        "); Put(Integer'Size); New_Line;
> 	Put("Integer'First       "); Put(Integer'First); New_Line;
> 	Put("Integer'Last        "); Put(Integer'Last); New_Line;
> 
> 	Put("Short_Integer'Size  "); Put(Short_Integer'Size); New_Line;
> 	Put("Short_Integer'First "); Put(Short_Integer'First); New_Line;
> 	Put("Short_Integer'Last  "); Put(Short_Integer'Last); New_Line;
> end Integer_Types;
> 

Integer'First is of type Integer; therefore overloading resolution can
resolve the Put to the one on Integer. However, Integer'Size is of type
Universal_Integer, i.e. the actual type is determined from context.
Since you have two acceptable contexts, it is ambiguous.

You can either qualifie the expression: Integer'(Integer'Size) or
specify explicitely which Put you want:
Integer_Text_IO.Put (Integer'Size);

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: ambiguous expression (cannot resolve "Put")
  2019-07-27  8:28 ` J-P. Rosen
@ 2019-07-27  9:09   ` cryintothebluesky
  0 siblings, 0 replies; 3+ messages in thread
From: cryintothebluesky @ 2019-07-27  9:09 UTC (permalink / raw)


OK thanks for the explanation, this makes sense now. So universal integer is not a distinct type and can be converted to any integer type by the compiler, depending on the context. So Integer'(Integer'Size) explicitly converts it to Integer and a matching Put() function is found.


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

end of thread, other threads:[~2019-07-27  9:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-27  7:32 ambiguous expression (cannot resolve "Put") cryintothebluesky
2019-07-27  8:28 ` J-P. Rosen
2019-07-27  9:09   ` cryintothebluesky

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