Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curly braces without variable declaration

Tags:

c

curly-braces

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();

like image 650
Dor Avatar asked Feb 27 '23 16:02

Dor


2 Answers

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.

like image 109
Khaled Alshaya Avatar answered Mar 02 '23 06:03

Khaled Alshaya


There is no need to use curly braces like this, but it helps readability.

It's a choice of style by the author, I suppose :)

like image 20
sergiom Avatar answered Mar 02 '23 06:03

sergiom