Discard (Value);
Discard
does nothing, but tells the compiler that the value
given as an argument is not further used. It can be applied, e.g.,
to routine parameters which are to be ignored, so no warning about
them will be given with -Wunused
, or when calling a function
and ignore its result.
An alternative for the latter case is to give the function the
ignorable
attribute. This is useful is the function's result
is expected to be ignored regularly. If, however, a result is
generally meaningful and only to be ignored in a particular case,
using Discard
is preferable.
Discard
is a GNU Pascal extension.
program DiscardDemo;
function Foo (a: Integer): Integer; begin WriteLn (a); Foo := a + 1 end;
{ Parameter `a' is there only to make the parameter list compatible to that of function `Foo'. } function Bar (a: Integer): Integer; begin Discard (a); { Tell the compiler that we intentionally do not use `a' in this function. } Bar := a + 1 end;
var c: Char; f: function (a: Integer): Integer;
begin Write ('With output? '); ReadLn (c); if LoCase (c) = 'y' then f := Foo else f := Bar; Discard (f (42)) { Call the function, but ignore its result } end.