What is Block Structure?


A block is a statement containing its own local data declaration. The concept of a block is originated with ALGOL. The block-structured language permits an array with adjustable length. The main feature of blocks is their bracketing structure (begin and end used in ALGOL) in which they can define their data. In 'C' language, the syntax of the block is −

{
   declaration statements;
}

where the braces limit the block. The characteristic of a block is its nesting structure. Delimiters mark the starting and end of the block. In 'C' language, the braces { } act as delimiters, while ALGOL uses begin and end. Delimiter ensures that the block is independent of one another or is nested inside the other. The nesting property is sometimes referred to as a block structure.

The most closely nested rule gives the scope of declaration −

  • The scope of a declaration in Block B contains B.
  • If a name x is used in block B but is not declared in B then using a declaration of x in an enclosing block B is in the scope of a declaration of x in an enclosing block B′ such that
    • B′ has a declaration of x and
    • B′ is more closely nested around B than any other block with the declaration of x.

Consider a C program −

The execution of the above block structure program using stack can be shown in the following way −

Block structured language like ALGOL, and PL/I permit adjustable arrays, i.e., of varying length. Therefore, it cannot store irregular size arrays in between activation records. It can allocate the flexible or variable arrays at one corner of the activation record or above the fixed-size data. A pointer to these adjustable arrays will be stored in a fixed position of the activation record.

Block structured program consists of the nested procedure. Sometimes, a procedure refers to data that is not declared in it, i.e., non-local data. Non-local data will not be available in its activation record. Non-local data of one activation record will be present in an activation record of some other procedure.

There are two methods to access Non-Local data for a procedure are as follows −

  • Static Link− In this method, a pointer called static link is attached with each procedure which points to the topmost activation record of that procedure that physically surrounds it in the program. So, Non-local data references for any procedure can be found out by descending chain of pointers to find all statically enclosing procedures.

  • Display− The display is an array of pointer which are maintained to speed up the access to non-local data.

Updated on: 08-Nov-2021

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements