LibSR:Assertions
From Maths
Stub grade: C
This page is a stub
This page is a stub, so it contains little or minimal information and is on a to-do list for being expanded.The message provided is:
Take time do document properly
Assertions
- LIBSR_ASSERT(expr,"message") - put these everywhere, they can easily be disabled. Default behaviour is a descriptive error message of where it failed and to raise a debug exception.
- LIBSR_ARRAY_ACCESS(arrayExpr,indexExpr,boundsExpr) - asserts that the index greater than or equal to zero and strictly less than the bound expression. By default outputs descriptive error message and raises debug signal.
- Think of it as arrayExpr[indexExpr] - it may be used inline, for example even LIBSR_ARRAY_ACCESS(thing,i,n) = whatever; works (will effectively be thing[i]=whatever;)
- If assertions are disabled it simply becomes arrayExpr[indexExpr]. Do not be afraid to put these everywhere!
To do
- LIBSR_ASSERT_POINTER_ALIGNMENT(ptr,alignment) - not sure if alignment will be bytes or a power of 2 yet. These would not be parts of expressions and would become nothing with exceptions disabled.
- When it comes to reading/writing chunks of memory, it becomes important to check that what you're reading from or writing to is within bounds (from a base to the size of object) there's macro in the vector experiment that does this.