18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

360 Scope of declared items<br />

There is a performance penalty to pay for this flexibility <strong>in</strong> access<strong>in</strong>g items at different lexical levels. This penalty<br />

is mostly evident <strong>in</strong> the lengthy code required to perform procedure entry and exit. Optimiz<strong>in</strong>g compiles can<br />

drastically simplify the code required for entry and exit to a procedure or function when only a simple nest<strong>in</strong>g<br />

structure is used.<br />

The ma<strong>in</strong> code complexity arises because procedures and functions may be called recursively. A recursive<br />

procedure or function will create each time it is called a new stack frame.<br />

The use of the class construct can drastically reduce the need to use heavily nested procedures.<br />

24.2 Self-assessment<br />

• How might a whole <strong>in</strong> the visibility of a variable <strong>in</strong> a program be created.<br />

• Why cannot a procedure or function be called which is <strong>in</strong> an <strong>in</strong>ner block to the current call<strong>in</strong>g position.<br />

• What procedures and <strong>in</strong>teger variables can code <strong>in</strong> the body of the procedures Ma<strong>in</strong>, Proc_A,<br />

Proc_B, and Proc_C access <strong>in</strong> the follow<strong>in</strong>g program.<br />

procedure Ma<strong>in</strong> is<br />

A : Integer;<br />

procedure Proc_A is<br />

B : Integer;<br />

procedure Proc_B is<br />

C : Integer;<br />

beg<strong>in</strong><br />

end Proc_B;<br />

procedure Proc_C is<br />

D : Integer;<br />

beg<strong>in</strong><br />

end Proc_C;<br />

beg<strong>in</strong><br />

end Proc_A;<br />

E : Integer;<br />

beg<strong>in</strong><br />

end Ma<strong>in</strong>;<br />

--Code;<br />

--Code;<br />

--Code;<br />

--Code<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!