4 ms·
It's closely coupled with rule #3. An array at least in the safety critical embedded software have a fixed size determined at initialization. You may have a
by gte525u 11y ago
It's closely coupled with rule #3. An array at least in the safety critical embedded software have a fixed size determined at initialization. You may have a sentinel value you're looking for, but, the loop should never exceed the preallocated size.
There are another set of arguments /against/ using stopping the loop at the sentinel values because it may make the software less deterministic. But, that's another topic.
- erikb 11y agoLess deterministic? Isn't it quite deterministic if something stops when a static limit is exceeded?
- victorNicollet 11y agoThis helps ensure that if your software runs in 10ms on the test data set, then it will always run in 10ms on all data sets. In general, it is recommended to avoid "best case" optimization, so that your critical software is always running with "worst case" performance. EDIT: On re-reading your message and the message it is responding to, I believe you are meaning opposite things by "sentinel".
- TickleSteve 11y agoAn example wold be to use memcpy() instead of strcpy(). memcpy() always copies n bytes, regardless of actual string size so is very deterministic and (commonly) inlined so is static. strcpy() on the other hand would loop infinitely until it found a null-terminator, it also is not deterministic. memcpy() is easily analysable. strcpy() isn't.