side effects, correction of previous goof 
Author Message
 side effects, correction of previous goof

Last week I broke my own rule and posted Ada without compiling it. Keith
caught the error (not much gets by him :-)

I used in an example

   Pre_Increment (I) + Post_Increment (I)

you can't do that in Ada, since out and in-out parameters are not permitted
for functions. There are two ways to get around it. In Ada 95, you can use
access parameters, and write (managed to spell that right this time, I
notice that I made the annoying mistake of right for write in my last post,
fingers running ahead of brain again!):

   Pre_Increment (I'Access) + Post_Increment (I'Access)

or, since Ada allows side effects in functions provided they are not
recorded in the function spec:

   Pre_Increment_I + Post_Increment_I

As I noted, the two languages are formally equivalent when it comes to
dealing with side effects. However, as is so often the difference between
C and Ada in practice, although there may be a formal equivalence, the
style in C, encouraged by the facile syntax of c++ and embedded use of
assignment, is to use side effects within expressions much more freely,
and hence to run into such situations as the above much more commonly.
The fact that macros can hide that this is happening (resulting in the
well known is_lower (c++) type of bug) aggravtaes this problem.

Either of the above two "correct" Ada attempts at causing the problem is
in fact rather forced, and quite unlikely to occur in real Ada programs.

Sat, 08 Nov 1997 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Correction of my previous posting.

2. Correction to previous post, asterik should be replaced with apostrophe

3. STD - correction to previous information that I have posted

4. Correction to previous post

5. minor correction to my previous post

6. ANNOUNCE: Winico 0.4 prerelease (correction from previous announcement)

7. Dialogs and side effects

8. Pattern for side effects

9. Skipping print preview side effect ArnĂ³r

10. Avoiding functions with side effects

11. INI file side effects

12. Functions without side effects (was Old confusion)


Powered by phpBB® Forum Software