Reputation: 383
I now have seen several times that in an explanation of syntax the phrase structured-block was used. For example:
#pragma omp single
structured-block
(This is from OpenMP, but that doesn't matter.)
Would the following two lines also count as a structured-block?
do_something1;
do_something2;
or only the first statement alone?
So, to put it shortly: What do they mean when saying structured-block?
Upvotes: 0
Views: 502
Reputation: 3256
Based on the documentation here:
A “structured block” is a single statement or a compound statement with a single entry at the top and a single exit at the bottom
Looking up the definition of a compound statement here:
A compound statement, or block, is a brace-enclosed sequence of statements and declarations.
Given this definition, do_something1;
would be the only one part of the structured block as a new "single" statement begins after that. On the other hand if you did
#pragma omp <directive>
{
do_something1;
do_something2;
}
it would have both in the structured block as its a "compound" statement.
Finally, note the definition stating single entry at the top and a single exit at the bottom
. This simply means that we should not have an intermediate exit/control-flow breaking point like a goto
statement, return
or throw error
in between.
Upvotes: 1
Reputation: 2853
structured-block is either a single statement, like
printf("Hello\n");
or a sequence of statements enclosed in curly braces:
{
printf("Hello ");
printf("World\n");
}
In addition, OpenMP requires "single entry, single exit", so that means that you cannot have a goto
or similar branching into the block and that you cannot have a branch leaving the block, e.g. goto
or in C++ an exception. Instead, the code needs to reach the closing curly brace.
Upvotes: 1