Compare commits
2 Commits
main
...
docs_updat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f868da636 | ||
|
|
5794aebe47 |
@@ -22,6 +22,7 @@ import hooksFloatManipPure from './md/hooks-float-manip-pure.md'
|
||||
import hooksFloatOnePure from './md/hooks-float-one-pure.md'
|
||||
import hooksFloatPure from './md/hooks-float-pure.md'
|
||||
import hooksGuardCalled from './md/hooks-guard-called.md'
|
||||
import hooksGuardCallNonConst from './md/hooks-guard-call-non-const.md'
|
||||
import hooksGuardInFor from './md/hooks-guard-in-for.md'
|
||||
import hooksGuardInWhile from './md/hooks-guard-in-while.md'
|
||||
import hooksHashBufLen from './md/hooks-hash-buf-len.md'
|
||||
@@ -70,6 +71,7 @@ const docs: { [key: string]: string } = {
|
||||
'hooks-float-one-pure': hooksFloatOnePure,
|
||||
'hooks-float-pure': hooksFloatPure,
|
||||
'hooks-guard-called': hooksGuardCalled,
|
||||
'hooks-guard-call-non-const': hooksGuardCallNonConst,
|
||||
'hooks-guard-in-for': hooksGuardInFor,
|
||||
'hooks-guard-in-while': hooksGuardInWhile,
|
||||
'hooks-hash-buf-len': hooksHashBufLen,
|
||||
|
||||
6
xrpl-hooks-docs/md/hooks-guard-call-non-const.md
Normal file
6
xrpl-hooks-docs/md/hooks-guard-call-non-const.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# hooks-guard-call-non-const
|
||||
|
||||
Only compile-time constants can be used as an argument in loop GUARD call. This check warns if a non compile-time constant is used.
|
||||
It also checks whether a compile-time constant is used as a first argument of `_g()` call and whether it is a unique value. If not - it warns.
|
||||
|
||||
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/loops-and-guarding)
|
||||
@@ -1,14 +1,35 @@
|
||||
# hooks-guard-in-for
|
||||
|
||||
A guard is a marker that must be placed in your code at the top of each loop. Consider the following for-loop in C:
|
||||
Consider the following for-loop in C:
|
||||
|
||||
```c
|
||||
#define GUARD(maxiter) _g(__LINE__, (maxiter)+1)
|
||||
|
||||
for (int i = 0; GUARD(3), i < 3; ++i)
|
||||
#define GUARD(maxiter) _g(__LINE__, (maxiter)+1)
|
||||
for (int i = 0; GUARD(3), i < 3; ++i)
|
||||
```
|
||||
|
||||
<BR/>
|
||||
This is the only way to satisfy the guard rule when using a for-loop in C.
|
||||
To satisfy the guard rule when using a for-loop in C guard should be
|
||||
placed either in the condition part of the loop, or as a first call in loop body, e.g.
|
||||
|
||||
```c
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
GUARD(3);
|
||||
}
|
||||
```
|
||||
|
||||
In case of nested loops, the guard limit value should be
|
||||
multiplied by a number of iterations in each loop, e.g.
|
||||
|
||||
```c
|
||||
for(int i = 0; GUARD(3), i < 3; ++i) {
|
||||
for (int j = 0; GUARD(17), j < 5; ++j)
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
(most descendant loop iterations + 1) * (each parent loops iterations) - 1
|
||||
```
|
||||
|
||||
This check will warn if the GUARD call is missing and also it will propose a GUARD value based on the for loop initial value,
|
||||
the increment and loop condition.
|
||||
|
||||
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/loops-and-guarding)
|
||||
|
||||
Reference in New Issue
Block a user