From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ae138939b724a2de,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Single element arrays as function parameters Date: Fri, 10 Jun 2011 22:11:49 +0200 Message-ID: <86ei31v43e.fsf@gareth.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net AaC2+jpKtcCvgymufBONkQllvm9C5bRDrZDbOnGVmN2+m9RCNb X-Orig-Path: gareth.avalon.lan!not-for-mail Cancel-Lock: sha1:Tba+IlQ8xqRTukD1olqB1Zk7I8A= sha1:0aEAy+nY+JbrbRe0HFAo+Vb4YJs= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:19736 Date: 2011-06-10T22:11:49+02:00 List-Id: I have the following function: function Creature (Name : in String; Race : in MM_Subtype; Level : in Positive; Player : in String) return Character_Ptr is C : Character_Ptr; Temp : Integer; begin C := new Player_Character; C.Creature_Name := To_Unbounded_String(Name); C.Creature_Type := Humanoid; C.Creature_Subtype := new MM_Subtype'(Race); C.Character_Level := Class_Level(Level); C.Player := To_Unbounded_String(Player); return C; end Creature; It will update the following record: type Creature is tagged record Creature_Name : Unbounded_String; Creature_Type : MM_Type; Creature_Subtype : access MM_Subtype; end record; (actually, it will update a derived type with a few extra fields, but that is not important right now). It works just fine when called like this: M := Init.Creature( Name => "Duergar", Creature_Type => Humanoid, Creature_Subtype => (Dwarf,Psionic) ); But when called like this M := Init.Creature( Name => "Dwarf", Creature_Type => Humanoid, Creature_Subtype => (Dwarf) ); The above call fails to compile: test_create.adb:11:13: no candidate interpretations match the actuals: test_create.adb:11:13: missing argument for parameter "Race" in call to "Creature" declared at games-rpg-dnd-creatures.ads:47 test_create.adb:11:13: missing argument for parameter "Level" in call to "Creature" declared at games-rpg-dnd-creatures.ads:44 test_create.adb:13:45: positional aggregate cannot have one component test_create.adb:13:45: ==> in call to "Creature" at games-rpg-dnd-creatures.ads:40 If I look at the language documentation, I'm guessing that this is because a single element array does not get recognised as being of type MM_Subtype, which is defined as type MM_Subtype is array(Natural range <>) of Possible_MM_Subtype; What *is* the best way to store an attribute which may be either a single enumeration element or a list of enumeration elements? Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.