comp.lang.ada
 help / color / mirror / Atom feed
* Single element arrays as function parameters
@ 2011-06-10 20:11 Mart van de Wege
  2011-06-10 20:54 ` J-P. Rosen
  2011-06-11 12:28 ` Peter C. Chapin
  0 siblings, 2 replies; 7+ messages in thread
From: Mart van de Wege @ 2011-06-10 20:11 UTC (permalink / raw)


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.



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

end of thread, other threads:[~2011-06-13 14:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 20:11 Single element arrays as function parameters Mart van de Wege
2011-06-10 20:54 ` J-P. Rosen
2011-06-10 21:28   ` Mart van de Wege
2011-06-10 21:58     ` Adam Beneschan
2011-06-10 22:24       ` Mart van de Wege
2011-06-11 12:28 ` Peter C. Chapin
2011-06-13 14:49   ` Adam Beneschan

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