-1

I often hear about the term of "compound statements" almost interchangeably used for a block, starting and ending with curly brackets of {}. I see no differences to a block.

So my Question is:

  • Is there a difference between a "block" and "compound statement"?

2 Answers2

1

To cite the actual C++ standard, ISO/IEC 14882:2017 (C++17), Section 9.3 "Compound statement or block":

9.3 Compound statement or block [stmt.block]

1 So that several statements can be used where one is expected, the compound statement (also, and equivalently, called “block”) is provided.

compound-statement: { statement-seqopt }

there is no difference between the terms of a block and a compound statement in their respective meaning.

You can use both terms interchangeably for a "compound" or sequence of statements (it may even be only one statement; the amount of statements doesn´t matter) starting by a "{" - opened curly bracket and terminating by a "}" - closed curly bracket.

Community
  • 1
  • 1
0

A "block" of code, delimited by { } to indicate entry-exit points, limits the liftetime of any variables defined inside the block to that block, wheras a "compound statement" might not unless it uses { } inside it. A function definition may be construed as a "named block" of code with an entry and exit points.

srinivirt
  • 286
  • 1
  • 6