Am 15.04.2019 um 01:19 schrieb Ryan Joseph:

On Apr 14, 2019, at 7:08 PM, Martin Frb <laza...@mfriebe.de> wrote:

Almost. assert takes the condition itself

assert(condition_that_must_be_true, 'error message')

so it would be
   assert(name<>'', 'requires "name <> ''''" failed for CreateHero');

You can already insert such asserts yourself. assert exists.

If you compile with -Sa then they are compiled in the code, otherwise not.
 From the compilers perspective isn’t it faster to test the condition first in 
an if statement so the assert function doesn’t get called? Assert tests for 
false also so it needs to invert the test to “name = ‘’” which is not how the 
“requires” statement is worded.
An Assert() might look like a mere procedure call, but it's in fact an intrinsic. If assertions are disabled ({$ASSERTIONS OFF}) then it completely does not exist and otherwise it's the check followed by a call to 'fpc_assert'.

Also an assertion "fires" if it's condition is False, so Assert() would do the same check as "requires" or "ensure" need:

requires
  Assigned(MyArg)

becomes

Assert(Assigned(MyArg), ...);

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to