I need to create a parameterized task in Ada, and the error I'm getting is: discriminants must have a discrete or access type.
Here is my code:
task type FEP_Con(Port_Num : Port_Name) is
entry Start;
end FEP_Con;
type FEP_Con_acc is access FEP_Con;
task body FEP_Con is
S_Port : Serial_Port;
Buffer : Ada.Streams.Stream_Element_Array(1..1024);
Last : Ada.Streams.Stream_Element_Offset;
Response_Str : Unbounded_String;
--cPort : Port_Name := "";
begin
accept Start;
Thanks in advance.
Though the type definition for "Port_Name" isn't provided, based on the discriminant name I presume it's a fixed-length string or Unbounded_String or somesuch. Neither of which are discrete or access types.
Discrete types are "either integer types or are defined by enumeration of their values (enumeration types)". RM 3.2[3]
An access type is a "pointer" type.
So for your task discriminant you can use some integer-based type--that doesn't necessarily mean derived or subtyped from Integer, but just a counting integer type, e.g. type Port_Name_IDs is range 1 .. 100;
Or you can define your Port_Names as an enumeration, e.g.:
type Port_Name is (Haifa, Amsterdam, Long_Beach);
Or define an access type referencing your existing Port_Name type, e.g.:
type Port_Name_Ref is access Port_Name;