Update documentation & add tests as per lastest changes
This commit is contained in:
1 parent
edbcecb272
commit
15d0b86c62
2 files changed
+11
-2
No files matched your search
@@ -5938,14 +5938,14 @@ However, you can use the break instruction to quit the block (the clear function
|
||||
and you can chain the M\_LET macro to create several different variables.
|
||||
|
||||
|
||||
##### M\_LET\_IF(init_code, test_code, clear_code)
|
||||
##### M\_LET\_IF(init_code, test_code, clear_code [, else_code] )
|
||||
|
||||
This macro defines the variable(s) in 'init_code',
|
||||
executes the next block of instructions where the variable(s) is(are) used if the initialization succeeds by testing 'test_code',
|
||||
then it executes the 'clear_code'.
|
||||
|
||||
'test_code' returns a boolean indicating if the initialization succeeds (true) or not.
|
||||
If the initialization fails, it won't call the 'clear_code'.
|
||||
If the initialization fails, it won't call the 'clear_code', but the 'else_code' if present.
|
||||
|
||||
The syntax of 'init_code' is the same as a for loop.
|
||||
|
||||
|
||||
@@ -206,6 +206,15 @@ static void test_let(void)
|
||||
*p = 4;
|
||||
}
|
||||
|
||||
M_LET_IF( assert(c++ == 7), (assert(c++ == 8), true), assert(c++ == 10), assert(0) ) {
|
||||
assert(c++ == 9);
|
||||
}
|
||||
M_LET_IF( assert(c++ == 11), (assert(c++ == 12), false), assert(0), assert(c++ == 13) ) {
|
||||
assert(0);
|
||||
}
|
||||
assert(c++ == 14);
|
||||
|
||||
c = 7;
|
||||
int *p = (int*)malloc(sizeof(int));
|
||||
assert(p != NULL);
|
||||
M_DEFER ( (assert(c++ == 8), free(p)) ) {
|
||||
|
||||
Reference in new issue
Block a user