1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-25 19:29:49 +00:00
millfork/docs/abi/undefined-behaviour.md

52 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2019-07-15 12:21:50 +00:00
[< back to index](../doc_index.md)
2018-04-02 22:21:26 +00:00
2018-01-04 00:15:04 +00:00
# Undefined behaviour
Since Millfork is only a middle-level programming language and attempts to eschew runtime checks in favour of performance,
there are many situation when the program may not behave as expected.
In the following list, "undefined value" means an arbitrary value that cannot be relied upon,
and "undefined behaviour" means arbitrary and unpredictable behaviour that may lead to anything,
even up to hardware damage.
* array overruns: indexing past the end of an array leads to undefined behaviour
2019-04-29 20:57:40 +00:00
* writing to arrays defined as `const`
2018-01-04 00:15:04 +00:00
* stray pointers: indexing a pointer that doesn't point to a valid object or indexing it past the end of the pointed object leads to undefined behaviour
2019-08-05 12:07:33 +00:00
* reading uninitialized variables: will return undefined values and, if the type is `bool`, may put the program in an invalid state
2018-01-04 00:15:04 +00:00
2018-01-30 16:38:32 +00:00
* reading variables used by return dispatch statements but not assigned a value: will return undefined values
2018-07-03 21:28:05 +00:00
* reading a loop variable after the loop without initializing it again: will return undefined values
2018-01-30 16:38:32 +00:00
* returning a value from a function by return dispatch to a function of different return type: will return undefined values
* passing an index out of range for a return dispatch statement
2018-01-04 00:15:04 +00:00
* stack overflow: exhausting the hardware stack due to excess recursion, excess function calls or excess stack-allocated variables
2018-01-18 21:35:25 +00:00
* on ROM-based platforms: writing to arrays
2018-06-04 14:24:18 +00:00
* on ROM-based platforms: using global variables with an initial value (they will not be initialized!)
2018-01-18 21:35:25 +00:00
* violating the safe assembly rules ([6502](../lang/assembly.md), [8080/LR35902/Z80](../lang/assemblyz80.md))
2018-01-04 00:15:04 +00:00
* violating the [safe reentrancy rules](../lang/reentrancy.md)
2018-06-08 22:05:17 +00:00
* when using modifying operators: calling non-pure functions in the left-hand-side index expression (like in `a[f()] += b`).
Currently, such functions may be evaluated either once or twice. This might be fixed in the future.
* when using modifying operators: calling functions on the right-hand-side index expression than modify any of the variables used on the left hand side
* when using `for` loops operators: calling non-pure functions in the range limits (like in `for i,f(),to,g()`).
Currently, such functions may be evaluated any number of times. This might be fixed in the future.
2019-07-15 00:06:23 +00:00
* jumping across the scope of for loop that uses a fixed list or across functions
2019-08-05 12:07:33 +00:00
* division by zero and modulo by zero
* decimal addition and subtraction of values that are not binary-coded decimals
2018-01-04 00:15:04 +00:00
The above list is not exhaustive.