Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions content/courses/intro-to-ada/chapters/subprograms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ call cannot be ignored; that is, a function call cannot be used as a statement.
If you want to call a function and do not need its result, you will still need
to explicitly store it in a local variable.

.. code:: ada run_button project=Courses.Intro_To_Ada.Subprograms.Quadruple
.. code:: ada compile_button project=Courses.Intro_To_Ada.Subprograms.Quadruple
:class: ada-expect-compile-error

function Quadruple (I : Integer)
return Integer;

function Quadruple (I : Integer)
return Integer is

Expand All @@ -224,17 +227,23 @@ to explicitly store it in a local variable.
return I * 2;
end Double;

Res : Integer := Double (Double (I));
-- ^ Calling the Double
-- function
Res : Integer;
begin
Double (I);
Double (Double (I));
-- ERROR: cannot use call to function
-- "Double" as a statement

Res := Double (Double (I));
-- OK: return value of Double is
-- assigned to Res

return Res;
end Quadruple;

A statement such as :ada:`Double (Double (I));` is wrong because we're not
assigning the return value to a variable |mdash| we can correct this statement
by writing :ada:`Res := Double (Double (I));`.

.. admonition:: In the GNAT toolchain

In GNAT, with all warnings activated, it becomes even harder to ignore the
Expand Down
Loading