Search code examples
ccurly-braces

Curly braces without variable declaration


Why sometimes C code gets wrapped with curly braces without declaring a variable in them? e.g. (from FreeRTOS source code, file 'tasks.c'):

portENTER_CRITICAL();
{
    xTicks = xTickCount;
}
portEXIT_CRITICAL();


Solution

  • This is just an inner scope. The benefit is that code shows your intent in that case. e.g. This scope is the critical section.