Skip to content

Commit a7064d3

Browse files
Code style: don't goto over variable declarations
Signed-off-by: Tom Cosgrove <[email protected]>
1 parent d5ccf32 commit a7064d3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kb/development/mbedtls-coding-standards.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ When it's unavoidable that a `size_t` must be passed as an `int` function parame
313313

314314
Use of `goto` is allowed in functions that have to do cleaning up before returning from the function even when an error has occurred. It can also be used to exit nested loops. In other cases the use of `goto` should be avoided.
315315

316+
Some compilers (e.g. IAR) issue warnings when a `goto` jumps over a variable declaration. In these cases, either hoist the variable to the top of the function, use a local block, or extract the code with this variable into a smaller `static` function. If hoisting a pointer, it must be initialized, to avoid potential code-paths where it may be used uninitialized.
317+
316318
### Exit early and prevent nesting
317319

318320
Structure functions to exit or `goto` the exit code as early as possible. This prevents nesting of code blocks and improves code readability.

0 commit comments

Comments
 (0)