comp.lang.ada
 help / color / mirror / Atom feed
From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: ambiguous expression (cannot resolve "Put")
Date: Sat, 27 Jul 2019 10:28:04 +0200
Date: 2019-07-27T10:28:04+02:00	[thread overview]
Message-ID: <qhh1uj$3me$1@dont-email.me> (raw)
In-Reply-To: <64bf79fa-b330-416f-9deb-de3f0830d994@googlegroups.com>

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

  reply	other threads:[~2019-07-27  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27  7:32 ambiguous expression (cannot resolve "Put") cryintothebluesky
2019-07-27  8:28 ` J-P. Rosen [this message]
2019-07-27  9:09   ` cryintothebluesky
replies disabled

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