3.10.1 Critical Functions and Critical Statements

Next: 3.10.2 Enabling and Disabling Up: 3.10 Enabling and Disabling Previous: 3.10 Enabling and Disabling Contents Index

## 3.10.1 Critical Functions and Critical Statements

A special keyword may be associated with a block or a function declaring it as critical. SDCC will generate code to disable all interrupts upon entry to a critical function and restore the interrupt enable to the previous state before returning. Nesting critical functions will need one additional byte on the stack for each call.

> `int foo () __critical`
> `{`
> `...`
> `...`
> `}`

The critical attribute maybe used with other attributes like reentrant.
The keyword critical may also be used to disable interrupts more locally:

> `__critical{ i++; }`

More than one statement could have been included in the block.