Ada Programming/Delimiters/*


Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Operator edit

Standard Operations edit

Arithmetic Multiplication edit

The "*" operator is defined as arithmetic multiplication for all numeric types.

function "*" (Left, Right : T) return T;
Usage edit
A : constant Float   := 5.0 * 2.0;  -- A is now 10.0
B : constant Integer := 5 * 2;      -- B is also 10
Working Example edit
File: operator_multiply.adb (view, plain text, download page, browse all)
with Ada.Text_IO;

procedure Operator_Multiply is
   A : constant Float   := 5.0 * 2.0;  -- A is now 10.0
   B : constant Integer := 5 * 2;      -- B is also 10

   package T_IO renames Ada.Text_IO;
   package F_IO is new  Ada.Text_IO.Float_IO (Float);
   package I_IO is new  Ada.Text_IO.Integer_IO (Integer);

begin
   T_IO.Put ("A = ");
   F_IO.Put (
      Item => A,
      Fore => 3,
      Aft  => 1,
      Exp  => 0);
   T_IO.New_Line;
   T_IO.Put ("B = ");
   I_IO.Put (
      Item  => B,
      Width => 3,
      Base  => 10);
   T_IO.New_Line;
end Operator_Multiply;

Common Non-Standard Operations edit

Character replication edit

A String is created where a single character is replicated n-times.

function "*" (Left : Natural; Right : Character) return String;

In addition to standard Strings this operator is also defined for Bounded_String and Unbounded_String.

Usage edit
A : constant String := 10 * 'X';  -- A is filled with 10 X
Working Example edit

The character replication operator is part of the Ada.Strings.Fixed package. You need to with and use the package to make the operator visible.

File: operator_multiply_2.adb (view, plain text, download page, browse all)
with Ada.Text_IO;
with Ada.Strings.Fixed;

procedure Operator_Multiply_2 is
   use Ada.Strings.Fixed;

   A : constant String := 10 * 'X';  -- A is filled with 10 X

   package T_IO renames Ada.Text_IO;

begin
   T_IO.Put_Line ("A = " & A);
end Operator_Multiply_2;

String replication edit

A String is created where a source string is replicated n-times.

function "*" (Left : Natural; Right : String) return String;

In addition to standard fixed strings this operator is also defined for Bounded_String and Unbounded_String.

Usage edit
A : constant String := 3 * "Hello ";  -- A is filled with 3 Hello
Working Example edit

The string replication operator is part of the Ada.Strings.Fixed package. You need to with and use the package to make the operator visible.

File: operator_multiply_3.adb (view, plain text, download page, browse all)
with Ada.Text_IO;
with Ada.Strings.Fixed;

procedure Operator_Multiply_3 is
   use Ada.Strings.Fixed; 

   A : constant String := 3 * "Hello ";  -- A is filled with 3 Hello.

   package T_IO renames Ada.Text_IO;

begin
   T_IO.Put_Line ("A = " & A);
end Operator_Multiply_3;

See also edit

Wikibook edit

Ada 95 Reference Manual edit

Ada 2005 Reference Manual edit



Ada Operators
and and then > + abs &
or or else >= - mod
xor = < * rem in
not /= <= ** / not in