home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / educ / progerrs.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  74.1 KB  |  2,029 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.               A Sample of Ada* Programmer Errors
  15.  
  16.  
  17.                   John B. Goodenough
  18.               Wang Institute of Graduate Studies
  19.                   Tyng Road
  20.                  Tyngsboro, MA 01879
  21.  
  22.                 March 6, 1986
  23.                 Interim Draft
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. * Ada is a registered trademark of the U. S. Government (Ada Joint Program
  58. Office)
  59.  
  60. Ada Programmer Errors                     6-Mar-86                 20:03:24 
  61.  
  62.  
  63.  
  64.                              TABLE OF CONTENTS
  65.  
  66.  
  67. 0.0  different uses of =>  . . . . . . . . . . . . . . . . . . . . . . . .   1
  68.  
  69. 2.3  illegal use of underscore . . . . . . . . . . . . . . . . . . . . . .   2
  70. 2.4.1  -1 is not a literal . . . . . . . . . . . . . . . . . . . . . . . .   2
  71. 2.5  one character string literals or character literals . . . . . . . . .   2
  72. 2.9  inadvertent use of reserved words . . . . . . . . . . . . . . . . . .   3
  73.  
  74. 3.2  anonymous array types . . . . . . . . . . . . . . . . . . . . . . . .   3
  75. 3.2.2  Using non-universal constants in number decls.  . . . . . . . . . .   3
  76. 3.3.1  types vs. subtypes; strong typing . . . . . . . . . . . . . . . . .   3
  77. 3.3.1  Using base type name in type definition . . . . . . . . . . . . . .   4
  78. 3.3.1(4)  type declarations declare distinct types . . . . . . . . . . . .   4
  79. 3.3.2  Attempt to use subtype as private type  . . . . . . . . . . . . . .   4
  80. 3.5.1  'FIRST of enumeration literal has position number zero  . . . . . .   5
  81. 3.5.5  'RANGE and 'LENGTH not defined for scalar types . . . . . . . . . .   5
  82. 3.5.5  VAL attribute does not depend on rep. clause  . . . . . . . . . . .   5
  83. 3.5.9  Failure to include range in fixed point declaration . . . . . . . .   5
  84. 3.5.9  Fixed point subtype declarations  . . . . . . . . . . . . . . . . .   6
  85. 3.6  Lower bounds of arrays not always 1 . . . . . . . . . . . . . . . . .   6
  86. 3.6  No partially constrained arrays . . . . . . . . . . . . . . . . . . .   6
  87. 3.6.2  no numeric operators for array types  . . . . . . . . . . . . . . .   6
  88. 3.6.3  Length of actual string parameter arguments . . . . . . . . . . . .   7
  89. 3.6.3(1)  the index subtype for STRING is Integer  . . . . . . . . . . . .   7
  90. 3.7  No anonymous array types for record components  . . . . . . . . . . .   7
  91. 3.7(5)  no sliding for record component initializations  . . . . . . . . .   7
  92. 3.7.1  NUMERIC_ERROR for unconstrained record objects  . . . . . . . . . .   8
  93. 3.8.1  Using an incomplete type prematurely  . . . . . . . . . . . . . . .   8
  94. 3.9(2)  basic declarations not allowed after bodies  . . . . . . . . . . .   8
  95. 3.9(6)  Activating a task whose body has not been elaborated . . . . . . .   9
  96.  
  97. 4.0.3  Using Pointers and .all . . . . . . . . . . . . . . . . . . . . . .   9
  98. 4.1.3  Using .all to access whole records  . . . . . . . . . . . . . . . .   9
  99. 4.3(4)  aggregates with only one component . . . . . . . . . . . . . . . .  10
  100. 4.3.2  Character literals vs string literals . . . . . . . . . . . . . . .  10
  101. 4.3.2  Rules for using others choice . . . . . . . . . . . . . . . . . . .  10
  102. 4.4  Can't parenthesize range  . . . . . . . . . . . . . . . . . . . . . .  11
  103. 4.5.4  precedence of unary minus . . . . . . . . . . . . . . . . . . . . .  11
  104. 4.9(8)  Size of a record is not static . . . . . . . . . . . . . . . . . .  11
  105.  
  106. 5.2  Failure to use aggregates in assignments  . . . . . . . . . . . . . .  11
  107. 5.2.1(2)  No sliding of array components in record aggregates  . . . . . .  12
  108. 5.4(2)  not all choices can be parenthesized . . . . . . . . . . . . . . .  12
  109. 5.4(4)  Use of RANGE attribute in loops and case statements  . . . . . . .  12
  110. 5.5  negative bounds for loop parameters . . . . . . . . . . . . . . . . .  13
  111.  
  112. 6.2  Slices used as actual parameters  . . . . . . . . . . . . . . . . . .  13
  113. 6.2(2)  Incorrect use of formal parameter modes  . . . . . . . . . . . . .  14
  114. 6.2(5)  Assignment to component designated by OUT parameter  . . . . . . .  14
  115. 6.3  ; instead of IS in subprogram bodies  . . . . . . . . . . . . . . . .  14
  116.  
  117. Ada Programmer Errors                     6-Mar-86                 20:03:24 
  118.  
  119.  
  120.  
  121. 6.3(2)  Bodies that use IS rather than semicolon . . . . . . . . . . . . .  14
  122. 6.3.1(5)  can't omit IN in parameter decl if it is present in body . . . .  15
  123. 6.3.2(4)  dependence on body due to INLINE . . . . . . . . . . . . . . . .  15
  124. 6.6(1)  Parameter names not considered in overloaded declarations  . . . .  15
  125.  
  126. 8.3  visibility of operators . . . . . . . . . . . . . . . . . . . . . . .  16
  127. 8.3  visibility rules for operators  . . . . . . . . . . . . . . . . . . .  15
  128. 8.3(15)  Object declaration hides outer procedure declaration  . . . . . .  17
  129. 8.3(18)  Need a use clause to get visibility of operators  . . . . . . . .  17
  130. 8.4(5)  Conflict with a name declared in Standard  . . . . . . . . . . . .  18
  131. 8.4(6)  Effect of USE on generic subprograms . . . . . . . . . . . . . . .  18
  132. 8.4(6)  Use clause and renamed exceptions  . . . . . . . . . . . . . . . .  18
  133. 8.5  ignoring constraints in renaming  . . . . . . . . . . . . . . . . . .  20
  134. 8.5  renaming task entries . . . . . . . . . . . . . . . . . . . . . . . .  19
  135.  
  136. 9.0  Deadlock because of exception propagation . . . . . . . . . . . . . .  20
  137. 9.1(4)  Can't use task type name in its own body . . . . . . . . . . . . .  21
  138. 9.2  Use task types instead of single tasks  . . . . . . . . . . . . . . .  21
  139. 9.4  Nested task termination and leaving block . . . . . . . . . . . . . .  22
  140. 9.4(13)  Termination of library tasks  . . . . . . . . . . . . . . . . . .  22
  141. 9.5  deadlock by mismatched entry indexes  . . . . . . . . . . . . . . . .  22
  142. 9.6  delay 2.5*minutes is illegal  . . . . . . . . . . . . . . . . . . . .  23
  143. 9.6(1)  Delay statments can be used in the main program  . . . . . . . . .  23
  144. 9.7.1  evaluation of guards  . . . . . . . . . . . . . . . . . . . . . . .  23
  145. 9.7.1(6)  "fairness" is not guaranteed . . . . . . . . . . . . . . . . . .  23
  146. 9.10  delay 0.0 can synchronize an abort . . . . . . . . . . . . . . . . .  24
  147.  
  148. 10.1(6)  recompiling a library subprogram body . . . . . . . . . . . . . .  24
  149. 10.1.1  A with clause is not like an Include . . . . . . . . . . . . . . .  25
  150. 10.1.1  confusion of with and use  . . . . . . . . . . . . . . . . . . . .  25
  151. 10.2  Spelling SEPARATE correctly  . . . . . . . . . . . . . . . . . . . .  25
  152. 10.2(5)  Overloaded subunits are illegal . . . . . . . . . . . . . . . . .  25
  153. 10.2(5)  Subunits cannot be operators  . . . . . . . . . . . . . . . . . .  26
  154. 10.5(3)  Failure to use pragma ELABORATE for generic units . . . . . . . .  26
  155.  
  156. 11.4.2  Handling exceptions raised in declarations . . . . . . . . . . . .  27
  157.  
  158. 12.1  Generics are not macros  . . . . . . . . . . . . . . . . . . . . . .  28
  159. 12.1  No out mode for generic formal objects . . . . . . . . . . . . . . .  27
  160. 12.1  no overloaded generic units  . . . . . . . . . . . . . . . . . . . .  27
  161. 12.1(2)  generic subprograms bodies can't be delared with generic parameter 28
  162.  
  163. 14.3  Associating two file variables with a terminal . . . . . . . . . . .  29
  164. 14.3  I/O calls in tasks . . . . . . . . . . . . . . . . . . . . . . . . .  28
  165. 14.3.5(3)  PUT at the end of the program . . . . . . . . . . . . . . . . .  29
  166. 14.3.6(3)  GET for chars skips line terminators  . . . . . . . . . . . . .  29
  167. 14.3.7(6)  Failing to advance after DATA_ERROR for INTEGER GET . . . . . .  29
  168. 14.3.9(6)  Failing to advance after DATA_ERROR for ENUM GET  . . . . . . .  29
  169.  
  170. BL 02.03  illegal use of underscore  . . . . . . . . . . . . . . . . . . .   2
  171. BL 02.09  inadvertent use of reserved words  . . . . . . . . . . . . . . .   3
  172. BL 03.02.02  Using non-universal constants in number decls.  . . . . . . .   3
  173.  
  174. Ada Programmer Errors                     6-Mar-86                 20:03:24 
  175.  
  176.  
  177.  
  178. BL 03.05.09  Fixed point subtype declarations  . . . . . . . . . . . . . .   6
  179. BL 04.04  Can't parenthesize range . . . . . . . . . . . . . . . . . . . .  11
  180. BL 06.03  ; instead of IS in subprogram bodies . . . . . . . . . . . . . .  14
  181. BL 06.03(02)  Bodies that use IS rather than semicolon . . . . . . . . . .  14
  182. BL 10.02  Spelling SEPARATE correctly  . . . . . . . . . . . . . . . . . .  25
  183. BL 10.02(05)  Overloaded subunits are illegal  . . . . . . . . . . . . . .  25
  184. BL 10.02(05)  Subunits cannot be operators . . . . . . . . . . . . . . . .  26
  185.  
  186. NC 02.05  one character string literals or character literals  . . . . . .   2
  187. NC 03.02  anonymous array types  . . . . . . . . . . . . . . . . . . . . .   3
  188. NC 03.03.01  types vs. subtypes; strong typing . . . . . . . . . . . . . .   3
  189. NC 03.03.01  Using base type name in type definition . . . . . . . . . . .   4
  190. NC 03.03.01(04)  type declarations declare distinct types  . . . . . . . .   4
  191. NC 03.03.02  Attempt to use subtype as private type  . . . . . . . . . . .   4
  192. NC 03.06  Lower bounds of arrays not always 1  . . . . . . . . . . . . . .   6
  193. NC 03.06  No partially constrained arrays  . . . . . . . . . . . . . . . .   6
  194. NC 03.06.03  Length of actual string parameter arguments . . . . . . . . .   7
  195. NC 03.08.01  Using an incomplete type prematurely  . . . . . . . . . . . .   8
  196. NC 05.02  Failure to use aggregates in assignments . . . . . . . . . . . .  11
  197. NC 06.02(02)  Incorrect use of formal parameter modes  . . . . . . . . . .  14
  198. NC 10.01.01  A with clause is not like an Include  . . . . . . . . . . . .  25
  199. NC 10.01.01  confusion of with and use . . . . . . . . . . . . . . . . . .  25
  200. NC 12.01  Generics are not macros  . . . . . . . . . . . . . . . . . . . .  28
  201.  
  202. NU 00.00  different uses of => . . . . . . . . . . . . . . . . . . . . . .   1
  203. NU 02.04.01  -1 is not a literal . . . . . . . . . . . . . . . . . . . . .   2
  204. NU 03.05.05  'RANGE and 'LENGTH not defined for scalar types . . . . . . .   5
  205. NU 03.05.09  Failure to include range in fixed point declaration . . . . .   5
  206. NU 03.06.02  no numeric operators for array types  . . . . . . . . . . . .   6
  207. NU 03.07  No anonymous array types for record components . . . . . . . . .   7
  208. NU 03.09(02)  basic declarations not allowed after bodies  . . . . . . . .   8
  209. NU 04.0.03  Using Pointers and .all  . . . . . . . . . . . . . . . . . . .   9
  210. NU 04.01.03  Using .all to access whole records  . . . . . . . . . . . . .   9
  211. NU 04.03(04)  aggregates with only one component . . . . . . . . . . . . .  10
  212. NU 04.03.02  Character literals vs string literals . . . . . . . . . . . .  10
  213. NU 04.05.04  precedence of unary minus . . . . . . . . . . . . . . . . . .  11
  214. NU 05.02.01(02)  No sliding of array components in record aggregates . . .  12
  215. NU 05.04(02)  not all choices can be parenthesized . . . . . . . . . . . .  12
  216. NU 05.05  negative bounds for loop parameters  . . . . . . . . . . . . . .  13
  217. NU 06.03.01(05)  can't omit IN in parameter decl if it is present in body   15
  218. NU 06.06(01)  Parameter names not considered in overloaded declarations  .  15
  219. NU 08.05  renaming task entries  . . . . . . . . . . . . . . . . . . . . .  19
  220. NU 12.01  No out mode for generic formal objects . . . . . . . . . . . . .  27
  221. NU 12.01  no overloaded generic units  . . . . . . . . . . . . . . . . . .  27
  222. NU 12.01(02)  generic subprograms bodies can't be delared with generic par  28
  223.  
  224. UC 04.03.02  Rules for using others choice . . . . . . . . . . . . . . . .  10
  225. UC 09.07.01  evaluation of guards  . . . . . . . . . . . . . . . . . . . .  23
  226.  
  227. UE 03.05.01  'FIRST of enumeration literal has position number zero  . . .   5
  228. UE 03.05.05  VAL attribute does not depend on rep. clause  . . . . . . . .   5
  229. UE 03.06.03(01)  the index subtype for STRING is Integer . . . . . . . . .   7
  230.  
  231. Ada Programmer Errors                     6-Mar-86                 20:03:24 
  232.  
  233.  
  234.  
  235. UE 03.07(05)  no sliding for record component initializations  . . . . . .   7
  236. UE 03.07.01  NUMERIC_ERROR for unconstrained record objects  . . . . . . .   8
  237. UE 03.09(06)  Activating a task whose body has not been elaborated . . . .   9
  238. UE 04.09(08)  Size of a record is not static . . . . . . . . . . . . . . .  11
  239. UE 05.04(04)  Use of RANGE attribute in loops and case statements  . . . .  12
  240. UE 06.02  Slices used as actual parameters . . . . . . . . . . . . . . . .  13
  241. UE 06.02(05)  Assignment to component designated by OUT parameter  . . . .  14
  242. UE 06.03.02(04)  dependence on body due to INLINE  . . . . . . . . . . . .  15
  243. UE 08.03  visibility of operators  . . . . . . . . . . . . . . . . . . . .  16
  244. UE 08.03  visibility rules for operators . . . . . . . . . . . . . . . . .  15
  245. UE 08.03(15)  Object declaration hides outer procedure declaration . . . .  17
  246. UE 08.03(18)  Need a use clause to get visibility of operators . . . . . .  17
  247. UE 08.04(05)  Conflict with a name declared in Standard  . . . . . . . . .  18
  248. UE 08.04(06)  Effect of USE on generic subprograms . . . . . . . . . . . .  18
  249. UE 08.04(06)  Use clause and renamed exceptions  . . . . . . . . . . . . .  18
  250. UE 08.05  ignoring constraints in renaming . . . . . . . . . . . . . . . .  20
  251. UE 09.0  Deadlock because of exception propagation . . . . . . . . . . . .  20
  252. UE 09.01(04)  Can't use task type name in its own body . . . . . . . . . .  21
  253. UE 09.02  Use task types instead of single tasks . . . . . . . . . . . . .  21
  254. UE 09.04  Nested task termination and leaving block  . . . . . . . . . . .  22
  255. UE 09.04(13)  Termination of library tasks . . . . . . . . . . . . . . . .  22
  256. UE 09.05  deadlock by mismatched entry indexes . . . . . . . . . . . . . .  22
  257. UE 09.06  delay 2.5*minutes is illegal . . . . . . . . . . . . . . . . . .  23
  258. UE 09.06(01)  Delay statments can be used in the main program  . . . . . .  23
  259. UE 09.07.01(06)  "fairness" is not guaranteed  . . . . . . . . . . . . . .  23
  260. UE 09.10  delay 0.0 can synchronize an abort . . . . . . . . . . . . . . .  24
  261. UE 10.01(06)  recompiling a library subprogram body  . . . . . . . . . . .  24
  262. UE 10.05(03)  Failure to use pragma ELABORATE for generic units  . . . . .  26
  263. UE 11.04.02  Handling exceptions raised in declarations  . . . . . . . . .  27
  264. UE 14.03  Associating two file variables with a terminal . . . . . . . . .  29
  265. UE 14.03  I/O calls in tasks . . . . . . . . . . . . . . . . . . . . . . .  28
  266. UE 14.03.05(03)  PUT at the end of the program . . . . . . . . . . . . . .  29
  267. UE 14.03.06(03)  GET for chars skips line terminators  . . . . . . . . . .  29
  268. UE 14.03.07(06)  Failing to advance after DATA_ERROR for INTEGER GET . . .  29
  269. UE 14.03.09(06)  Failing to advance after DATA_ERROR for ENUM GET  . . . .  29
  270.  
  271. Ada Programmer Errors                     6-Mar-86             20:03:24   0
  272. Introduction
  273.  
  274.  
  275.  
  276.  
  277. This document contains a set of errors that have been reported to me after I
  278. asked people to tell me about programming errors they have made or observed.
  279. Some of the errors have also been found by inspecting vendor error reports,
  280. looking at just those error reports where the compiler was correct.
  281.  
  282. I have found that Ada-related programming errors can be usefully classified as
  283. follows.  These classes are shown in the Table of Contents and for each error.
  284.  
  285.         .  PERCEIVED NON-UNIFORMITIES (NU) in the language: exceptions to
  286.            rules that are in the minds of programmers, e.g.,
  287.     
  288.                 .  the precedence of unary minus is different from the
  289.                    precedence of other unary operators (although the same
  290.                    as the precedence of binary minus)
  291.  
  292.         .  NEW CONCEPTS (NC): differences from previously used programming
  293.            languages that cause confusion, e.g.,
  294.  
  295.                 .  each type declaration declares a distinct type
  296.  
  297.         .  UNAVOIDABLE COMPLEXITIES (UC): complex rules that trip up the
  298.            everyday programmer, e.g.,
  299.  
  300.                 .  rules for use of OTHERS in array aggregates
  301.  
  302.         .  BLUNDERS (BL): mistakes that are easy to make even though the
  303.            rules are clear, e.g., 
  304.  
  305.                 .  inadvertent use of reserved words as in
  306.  
  307.                    type Direction is (Forward, Reverse, Up, Down, Left, Right);
  308.  
  309.         .  UNEXPECTED EFFECTS (UE): unappreciated consequences of rules,
  310.            leading to subtle bugs in programs, e.g.,
  311.  
  312.                 .  effect of attempting to read the sequence 
  313.  
  314.                         13 16.2 
  315.  
  316.                    with GET instantiated for type INTEGER.
  317.  
  318. The list of errors, as reported, follows, sorted in Reference Manual order.
  319.  
  320. Ada Programmer Errors                     6-Mar-86             20:03:24   1
  321. 00.00
  322.  
  323.  
  324.  
  325.  
  326.  
  327. *****************************************************************************
  328.  
  329. !section 00.00                                                       ER-00005
  330. !class NU
  331. !topic different uses of =>
  332. !experience none
  333.  
  334. The students with very little programming experience (usually only Basic)
  335. also report an interesting problem.  They cannot seem to get the meaning
  336. of the compound delemeter arrow (=>) because it is used in so many places...
  337.  
  338.         case x is
  339.            when 1 => ...
  340.  
  341.         exception
  342.            when Constraint_Error => ...
  343.  
  344.         A : array (1 .. 10) of integer;
  345.         begin
  346.                 A := (1 .. 3 => 2, 5 ! 7 => 3, others => 8);
  347.  
  348.         text_io.put (file => f, item => "hi john... are you at wang now?");
  349.  
  350. *****************************************************************************
  351.  
  352. !section 00.00                                                       ER-00082
  353. !class NU
  354. !topic different uses of =>
  355.  
  356. John Goodenough has noted in his survey that the use of the => operator
  357. tends to cause problems for those who are new to Ada.  This is accompanied
  358. by a perception that it is used differently in different contexts.  I
  359. believe this perception is incorrect; the use of the symbol is completely
  360. uniform.  In general, its use in the form <name> => <value>.
  361.  
  362. Why, then, do people have so much trouble with it?  (And I had trouble with
  363. it, too, when I first encountered it.)  The answer, I maintain, is because
  364. the symbol looks like an arrow, and that arrow points in the wrong direction.
  365.  
  366. An arrow looks like an assignment, and we assign values to names, not vice
  367. versa.
  368.  
  369. Since <= is not available, I think a direction neutral symbol, perhaps ==,
  370. would have been a better choice.  It is perhaps too late to make this change
  371. now; on the other hand, perhaps later versions of the language could support
  372. it as an alternative.
  373.  
  374.  
  375. Ada Programmer Errors                     6-Mar-86             20:03:24   2
  376. 02.03
  377.  
  378.  
  379. *****************************************************************************
  380.  
  381. !section 02.03                                                       ER-00023
  382. !class BL
  383. !topic illegal use of underscore
  384.  
  385. Invalid Identifiers and Numeric Literals:
  386.  
  387.   A__B, A_, _A, 3_, 3__0, 3_.0, 3._0, etc.
  388.  
  389. *****************************************************************************
  390.  
  391. !section 02.04.01                                                    ER-00083
  392. !class NU
  393. !topic -1 is not a literal
  394.  
  395. -1 is not a literal but instead is an expression.  Usually this doesn't make
  396. any difference, but it does make a difference when you are using a numeric
  397. type that has been declared in a package:
  398.  
  399.         package P is
  400.             type My_Integer is range 1..100;
  401.         end P;
  402.  
  403.         X : P.My_Integer := 1;      -- okay
  404.         Y : P.My_Integer := -1;     -- illegal
  405.  
  406. The "-" operator is not directly visible because there is no use clause for P.
  407. The fact that the operators for My_Integer are not visible is not so confusing
  408. when one writes what looks like an expression, e.g.:
  409.  
  410.         Z : Boolean := X < Y;       -- illegal; "<" not visible
  411.  
  412. At least here it's clear that "<" is being used as an operator.  But
  413. programmers familiar with other languages are not always used to thinking of
  414. -1 as an expression containing an operator.  The illegality of Y's
  415. initialization expression comes as a shock!
  416.  
  417. *****************************************************************************
  418.  
  419. !section 02.05                                                       ER-00026
  420. !class NC
  421. !topic one character string literals or character literals
  422.  
  423.         procedure P is
  424.           C : Character := 'z';
  425.           S : String(1..1);
  426.         begin
  427.           S := C;
  428.           C := S;
  429.           C := "z";
  430.           S := 'z';
  431.         end P;
  432.  
  433. Incompatible types problem (easily corrected though). Incorrect use of
  434.  
  435. Ada Programmer Errors                     6-Mar-86             20:03:24   3
  436. 02.05
  437.  
  438.  
  439. quotation characters (easily corrected).
  440.  
  441. *****************************************************************************
  442.  
  443. !section 02.09                                                       ER-00018
  444. !class BL
  445. !topic inadvertent use of reserved words
  446.  
  447.         type Greek_Letters is (Alpha, Beta, Gamma, Delta, Epsilon);
  448.         type Direction is (Forward, Reverse, Up, Down);
  449.         type Digits is range 0 .. 9;
  450.  
  451. Thou shalt not use the reserved words in vain.
  452.  
  453. *****************************************************************************
  454.  
  455. !section 03.02                                                       ER-00024
  456. !class NC
  457. !topic anonymous array types
  458.  
  459.         A1, A2 : array(1 .. 10) of Boolean;
  460.          . . .
  461.         A1 := A2;
  462.  
  463. The old anonymous array type problem.
  464.  
  465. *****************************************************************************
  466.  
  467. !section 03.02.02                                                    ER-00020
  468. !class BL
  469. !topic Using non-universal constants in number decls.
  470.  
  471.         Var1 : constant Integer := 3;
  472.         Var2 : constant Integer := 4;
  473.         Var3 : constant := Var1 + Var2;
  474.  
  475. One cannot convert from a named type to a universal type (its a one-way
  476. street only).
  477.  
  478. [Actually, can use Integer'Pos(Var1) + Integer'Pos(Var2). JBG]
  479.  
  480. *****************************************************************************
  481.  
  482. !section 03.03.01                                                    ER-00004
  483. !class NC
  484. !topic types vs. subtypes; strong typing
  485. !experience students
  486.  
  487. the most common problem my students tell me about has to do with
  488. the difference between base types and subtypes.  For example...
  489.  
  490.         function factorial (of_n : natural) return natural;
  491.  
  492.         type numbers is range 1 .. 10;
  493.         n : numbers := 3;
  494.  
  495. Ada Programmer Errors                     6-Mar-86             20:03:24   4
  496. 03.03.01
  497.  
  498.  
  499.         f : natural;
  500.         begin
  501.                 f := factorial (n);
  502.  
  503. This will not compile.  They seem to think that all integer types should be
  504. subtypes of Integer and Integer should contain all possible integer values for
  505. a specific implementation.  It is the people with Fortran backgrounds who
  506. really have trouble with this and strong typing in general.
  507.  
  508. *****************************************************************************
  509.  
  510. !section 03.03.01                                                    ER-00016
  511. !class NC
  512. !topic Using base type name in type definition
  513.  
  514.         type I is Integer range 1 .. 10;
  515.  
  516. One cannot create a base type using another base type. Typically three
  517. solutions to this problem are:
  518.  
  519.           type I is range 1 .. 10;
  520.           type I is new Integer range 1 .. 10;
  521.           subtype I is Integer range 1 ..10;
  522.  
  523. *****************************************************************************
  524.  
  525. !section 03.03.01 (04)                                               ER-00054
  526. !class NC
  527. !topic type declarations declare distinct types
  528.  
  529. A programmer wrote:
  530.  
  531.         procedure TEST is
  532.             type A_9 is array (1..9) of CHARACTER;
  533.             type A_18 is array (1..18) of CHARACTER;
  534.  
  535.             A : A_9;
  536.             B : A_18;
  537.         begin
  538.             B := A & A;         -- illegal
  539.  
  540. In this case, the programmer forgot that A_9 and A_18 are distinct types and
  541. that subtype declarations should be used (or the STRING type).
  542.  
  543. *****************************************************************************
  544.  
  545. !section 03.03.02                                                    ER-00076
  546. !class NC
  547. !topic Attempt to use subtype as private type
  548.  
  549.   EXAMPLE:
  550.  
  551.         package foo is
  552.  
  553.  
  554. Ada Programmer Errors                     6-Mar-86             20:03:24   5
  555. 03.03.02
  556.  
  557.  
  558.                 subtype anything is private;
  559.  
  560.         private
  561.  
  562.                 subtype anything is ... -- Oops! I can't do that.
  563.  
  564.         end foo;
  565.  
  566.   This is not currently in the language standard, but I suspect that it may
  567.   be considered as possibility for future versions.  Using a subtype
  568.   as a private type is so intuitive to me, I sometimes find it difficult to
  569.   work around since it is not part of the language.
  570.  
  571. *****************************************************************************
  572.  
  573. !section 03.05.01                                                    ER-00030
  574. !class UE
  575. !topic 'FIRST of enumeration literal has position number zero
  576.  
  577.         some_enumeration_type'POS(same_enumeration_type'FIRST) = 0  ???
  578.  
  579. Many programmers believe that this expression equals 1, most notably for
  580. CHARACTER'POS(CHARACTER'FIRST). This causes many tricky algorithmic problems
  581. which take a novice a long time to debug.
  582.  
  583. *****************************************************************************
  584.  
  585. !section 03.05.05                                                    ER-00009
  586. !class NU
  587. !topic 'RANGE and 'LENGTH not defined for scalar types
  588.  
  589. It seems inconsistent that the attributes 'first, 'last, 'range, and 'length
  590. apply to arrays, but only 'first and 'last also apply to scalars.
  591.  
  592. *****************************************************************************
  593.  
  594. !section 03.05.05                                                    ER-00031
  595. !class UE
  596. !topic VAL attribute does not depend on rep. clause
  597.  
  598. The VAL attribute works in logical terms. In the presence of a rep. spec., the
  599. VAL attribute will not return the value specified in that rep. spec. but will
  600. return the position number.
  601.  
  602. *****************************************************************************
  603.  
  604. !section 03.05.09                                                    ER-00036
  605. !class NU
  606. !topic Failure to include range in fixed point declaration
  607.  
  608.         type My_Fixed is delta 0.01;
  609.  
  610. A base type of a fixed point type must state an explicit range. Note that
  611. floating point base types need not state a range.
  612.  
  613.  
  614. Ada Programmer Errors                     6-Mar-86             20:03:24   6
  615. 03.05.09
  616.  
  617.  
  618. *****************************************************************************
  619.  
  620. !section 03.05.09                                                    ER-00037
  621. !class BL
  622. !topic Fixed point subtype declarations
  623.  
  624.         type My_Fixed is delta 0.1 range 1.0 .. 2.0;
  625.         subtype Sub_Fixed is My_Fixed delta 0.01 range 0.0 .. 3.0;
  626.  
  627.         type My_Float is digits 2 range 1.0 .. 2.0;
  628.         subtype Sub_Float is My_Float digits 3 range 0.0 .. 3.0;
  629.  
  630. The subtypes will cause CONSTRAINT_ERROR to be raised since they each specify
  631. a greater accuracy and range of values than their respective base types.
  632.  
  633. *****************************************************************************
  634.  
  635. !section 03.06                                                       ER-00033
  636. !class NC
  637. !topic No partially constrained arrays
  638.  
  639.         type A is array(BOOLEAN, INTEGER range <>) of CHARACTER;
  640.  
  641. One cannot define an array type which has constrained and unconstrained
  642. indices mixed.
  643.  
  644. *****************************************************************************
  645.  
  646. !section 03.06                                                       ER-00077
  647. !class NC
  648. !topic Lower bounds of arrays not always 1
  649.  
  650.   EXAMPLE:
  651.  
  652.         procedure foo (str: in string) is
  653.         begin
  654.           for i in 1..str'length loop
  655.              str(i) := ' ';
  656.           end loop;
  657.         end foo;
  658.  
  659.   The correction to this is to use the 'FIRST and 'LAST attributes to
  660.   dynamically determine the bounds of the array.
  661.  
  662. *****************************************************************************
  663.  
  664. !section 03.06.02                                                    ER-00010
  665. !class NU
  666. !topic no numeric operators for array types
  667.  
  668. It seems inconsistent that the operators NOT, AND, OR, and XOR are implicitly
  669. defined on any boolean type or array of boolean types, but the implicit
  670. operators for numeric types are not defined for arrays of numeric types.
  671.  
  672.  
  673. Ada Programmer Errors                     6-Mar-86             20:03:24   7
  674. 03.06.03
  675.  
  676.  
  677. *****************************************************************************
  678.  
  679. !section 03.06.03                                                    ER-00043
  680. !class NC
  681. !topic Length of actual string parameter arguments
  682.  
  683. Whether its due to laziness or misunderstanding I don't know, but I frequently
  684. see functions which take strings as arguments using s'last for s'length or
  685. less often assuming s'first = 1.
  686.  
  687. *****************************************************************************
  688.  
  689. !section 03.06.03 (01)                                               ER-00070
  690. !class UE
  691. !topic the index subtype for STRING is Integer
  692.  
  693. Consider:
  694.  
  695.         subtype Line_Length is Long_Integer range 0..80;
  696.         X : String (1 .. Line_Length'Last);
  697.  
  698. This is illegal since the LAST attribute returns a result of type Line_Length'
  699. Base, which is not the predefined type INTEGER.
  700.  
  701. *****************************************************************************
  702.  
  703. !section 03.07                                                       ER-00025
  704. !class NU
  705. !topic No anonymous array types for record components
  706.  
  707.         type R is record
  708.           . . .
  709.           Arr : array(1 .. 10) of Boolean;
  710.         end R;
  711.  
  712. No anonymous array types allowed in a record type.
  713.  
  714. *****************************************************************************
  715.  
  716. !section 03.07    (05)                                               ER-00080
  717. !class UE
  718. !topic no sliding for record component initializations
  719.  
  720.     type Rec is
  721.         record
  722.             D : String (1..3) := X(3..5);   -- C_E
  723.         end;
  724.  
  725. Constraint_Error gets raised for the default initialization because 3.2.1(16)
  726. does not allow an implicit subtype conversion (which would cause the bounds to
  727. "slide" to 1..3).
  728.  
  729.  
  730. Ada Programmer Errors                     6-Mar-86             20:03:24   8
  731. 03.07.01
  732.  
  733.  
  734. *****************************************************************************
  735.  
  736. !section 03.07.01                                                    ER-00059
  737. !class UE
  738. !topic NUMERIC_ERROR for unconstrained record objects
  739.  
  740. Several users reported confusion at receiving NUMERIC_ERROR when allocating
  741. an object of type PACKET:
  742.  
  743.         type Packet (Size : Positive := 20) is
  744.             record
  745.                 data : String (1..Size);
  746.             end record;
  747.  
  748.         P : Packet;             -- NUMERIC_ERROR raised here
  749.  
  750. An implementation is allowed to raise NUMERIC_ERROR since the amount of space
  751. that needs to be allocated for P is Postive'Last characters plus space for
  752. the discriminant.  In computing Positive'Last + Positive'Size, NUMERIC_ERROR
  753. can be raised because the result is greater than Integer'Last (see 11.1(6)).
  754.  
  755. If NUMERIC_ERROR is not raised, STORAGE_ERROR might be, since a lot of space
  756. is likely to be occupied by POSITIVE'LAST characters.
  757.  
  758. *****************************************************************************
  759.  
  760. !section 03.08.01                                                    ER-00021
  761. !class NC
  762. !topic Using an incomplete type prematurely
  763.  
  764.         type Link;
  765.         type Node is
  766.           record
  767.             . . .
  768.             Next : Link;
  769.           end record;
  770.         type Link is access Node;
  771.  
  772. The incomplete type declaration should be used for Node, not Link.
  773.  
  774. *****************************************************************************
  775.  
  776. !section 03.09    (02)                                               ER-00044
  777. !class NU
  778. !topic basic declarations not allowed after bodies
  779.  
  780. Not listed in your summary was the problem I sent to info-ada of
  781. basic-declarations not allowed after later-declarations.  I really think this
  782. is a source of errors in Ada (even though my original message had the heat
  783. turned up to flame level.)
  784.  
  785.  
  786. Ada Programmer Errors                     6-Mar-86             20:03:24   9
  787. 03.09(06)
  788.  
  789.  
  790. *****************************************************************************
  791.  
  792. !section 03.09    (06)                                               ER-00060
  793. !class UE
  794. !topic Activating a task whose body has not been elaborated
  795.  
  796.         task type Actor is
  797.             ...
  798.         end Actor;
  799.  
  800.         type Actor_Ptr is access Actor;
  801.  
  802.         actor_Ptrs : array (1..10) of Actor_Ptr := (1..10 => new Actor);
  803.             -- PROGRAM_ERROR raised here
  804.  
  805.         task body Actor is ... end;
  806.  
  807. PROGRAM_ERROR will be raised because the body of Actor has not been elaborated
  808. when the allocator is executed.
  809.  
  810. *****************************************************************************
  811.  
  812. !section 04.0.03                                                     ER-00040
  813. !class NU
  814. !topic Using Pointers and .all
  815.  
  816. Also, some programmers still haven't got the difference down between the
  817. following two if-then conditions:
  818.  
  819.           type Access_R is access R;
  820.           A1, A2 : Access_R := . . .;
  821.  
  822.           if A1 = A2 then . . . end if;
  823.                     vs.
  824.           if A1.all = A2.all then . . . end if;
  825.  
  826. *****************************************************************************
  827.  
  828. !section 04.01.03                                                    ER-00039
  829. !class NU
  830. !topic Using .all to access whole records
  831.  
  832.         type R is
  833.           record
  834.             . . .
  835.           end record;
  836.         . . .
  837.         R1, R2 : R;
  838.         . . .
  839.         if R1.all = R2.all then . . . end if;
  840.  
  841. The ".all" suffix applies only to access values. When dealing with record
  842. objects, simply stating the object without a selected component is equivalent
  843. to a ".all" semantics for access values.
  844.  
  845.  
  846. Ada Programmer Errors                     6-Mar-86             20:03:24  10
  847. 04.03(04)
  848.  
  849.  
  850. *****************************************************************************
  851.  
  852. !section 04.03    (04)                                               ER-00068
  853. !class NU
  854. !topic aggregates with only one component
  855.  
  856. An aggregate containing only one component must be given in named notation,
  857. even when the context clearly indicates that an aggregate is meant.  For
  858. example,
  859.  
  860.         type Rec is
  861.             record
  862.                 C : Integer;
  863.             end record;
  864.  
  865.         type Rec_Rec is
  866.             record
  867.                 I : Integer;
  868.                 D : Rec;
  869.             end record;
  870.  
  871.         X : Rec_Rec := (1, (3));        -- illegal
  872.  
  873. The aggregate for component D must be written as (C => 3).
  874.  
  875. *****************************************************************************
  876.  
  877. !section 04.03.02                                                    ER-00014
  878. !class NU
  879. !topic Character literals vs string literals
  880.  
  881. Another trivial point: for STRINGS (arrays of CHARACTER), notice the
  882. difference of use:
  883.  
  884.         A_SMALL_STRING : STRING(1..1) := (others => ' ');
  885.      begin
  886.         A_SMALL_STRING := " ";
  887.  
  888. *****************************************************************************
  889.  
  890. !section 04.03.02                                                    ER-00038
  891. !class UC
  892. !topic Rules for using others choice
  893.  
  894.         type My_Array is array(INTEGER range 1 .. 10) of BOOLEAN;
  895.         . . .
  896.         A : My_Array := (1 .. 3 => FALSE, others => TRUE);
  897.  
  898. Cannot use an others clause in the presence of named notation where one or
  899. more choices represents a range of values. The tricky rules on the use of an
  900. others clause play havic with Ada programmers. Some even get so frustrated as
  901. to how/where an others clause can appear that they simply never try to use it.
  902. The rules should be made clear to these programmers (described at their own
  903. level -- they cannot understand the language of the ARM).
  904.  
  905.  
  906. Ada Programmer Errors                     6-Mar-86             20:03:24  11
  907. 04.04
  908.  
  909.  
  910. *****************************************************************************
  911.  
  912. !section 04.04                                                       ER-00015
  913. !class BL
  914. !topic Can't parenthesize range
  915.  
  916.         C : Character;
  917.          . . .
  918.         if C in ('A' .. 'Z') then . . . end if;
  919.  
  920. One cannot parenthesize the range for a membership test.
  921.  
  922. *****************************************************************************
  923.  
  924. !section 04.05.04                                                    ER-00008
  925. !class NU
  926. !topic precedence of unary minus
  927.  
  928. The low precedence of unary minus would surprise those with a math background,
  929. I would think.  -11 mod 5 is interpreted as -(11 mod 5) which is -1.  The
  930. other interpretation (-11) mod 5 equals 4.
  931.  
  932. *****************************************************************************
  933.  
  934. !section 04.09    (08)                                               ER-00045
  935. !class UE
  936. !topic Size of a record is not static
  937.  
  938. For an appropriate record type declaration:
  939.  
  940.         for FOO'SIZE use 4*SYSTEM.STORAGE_UNIT;
  941.         for BAR use
  942.             record
  943.                 COMPONENT at 0 range 0 .. FOO'SIZE-1;   -- illegal
  944.             end record;
  945.  
  946. The use of FOO'SIZE is illegal because FOO'SIZE is non-static; the prefix of
  947. the attribute is not a scalar type, as 4.9 requires.
  948.  
  949. *****************************************************************************
  950.  
  951. !section 05.02                                                       ER-00042
  952. !class NC
  953. !topic Failure to use aggregates in assignments
  954.  
  955. Pascal programmers also sometimes write record assignments as a series of
  956. field assignments, including the discriminant, instead of writing an aggregate
  957. assignment.
  958.  
  959.  
  960. Ada Programmer Errors                     6-Mar-86             20:03:24  12
  961. 05.02.01(02)
  962.  
  963.  
  964. *****************************************************************************
  965.  
  966. !section 05.02.01 (02)                                               ER-00058
  967. !class NU
  968. !topic No sliding of array components in record aggregates
  969.  
  970.         type R (D : Natural) is
  971.             record
  972.                 C : String (1..D);
  973.             end record;
  974.  
  975.         S : String (1..20) := ...;
  976.  
  977.         V1 := R(10) := (D => 10, C => S(1..10));     -- ok
  978.         V2 := R(10) := (D => 10, C => S(4..13));     -- exception
  979.  
  980. The second aggregate raises CONSTRAINT_ERROR because the bounds 4..13 don't
  981. match C's bounds of 1..10.
  982.  
  983. This shows that aggregate assignment is not equivalent to component by
  984. component assignment, since
  985.  
  986.         V2.C := S(4..13);
  987.  
  988. does not raise an exception.
  989.  
  990. *****************************************************************************
  991.  
  992. !section 05.04    (02)                                               ER-00073
  993. !class NU
  994. !topic not all choices can be parenthesized
  995.  
  996. Consider the following case statement:
  997.  
  998.         case X is
  999.             when ('_') => ...
  1000.             when ('/') => ...
  1001.             when ('0'..'9') => ...      -- illegal
  1002.  
  1003. The last choice is illegal because ranges cannot be parenthesized, but simple
  1004. expressions, such as '_' can be.
  1005.  
  1006. *****************************************************************************
  1007.  
  1008. !section 05.04    (04)                                               ER-00049
  1009. !class UE
  1010. !topic Use of RANGE attribute in loops and case statements
  1011.  
  1012. Consider the following example:
  1013.  
  1014.         declare
  1015.             A : array (0..2) of INTEGER;
  1016.         begin
  1017.             for I in A'RANGE loop       -- where A is an array, of course
  1018.                 case I is               -- I is NONSTATIC
  1019.  
  1020. Ada Programmer Errors                     6-Mar-86             20:03:24  13
  1021. 05.04(04)
  1022.  
  1023.  
  1024.                     when 0 => ...
  1025.                     when 1 => ...
  1026.                     when 2 => ...
  1027.                 end case;               -- missing OTHERS
  1028.             end loop;
  1029.         end;
  1030.  
  1031. The case statement is illegal because A'RANGE is non-static.  Hence, the loop
  1032. parameter has a non-static subtype, and the choices in the case statement
  1033. must cover the full range of the index base type, INTEGER.
  1034.  
  1035. *****************************************************************************
  1036.  
  1037. !section 05.05                                                       ER-00078
  1038. !class NU
  1039. !topic negative bounds for loop parameters
  1040.  
  1041. I have been reluctant to submit to your collection because I am fearful
  1042. that my contribution would be construed as a vote to alter the language,
  1043. and in every case I have come across, I feel the language is right and
  1044. should not be changed.  Nevertheless, allow me to throw in the following:
  1045.  
  1046.   for I in -5 .. 5 loop
  1047.  
  1048. which is a no-no unless you specify the range type (presumably Integer).
  1049.  
  1050. *****************************************************************************
  1051.  
  1052. !section 06.02                                                       ER-00006
  1053. !class UE
  1054. !topic Slices used as actual parameters
  1055.  
  1056.         function string_eq(left, right: string) return boolean is
  1057.         --returns true iff the two string parameters have the same value.
  1058.         begin
  1059.            if left'length /= right'length then return false; end if;
  1060.            for i in left'range loop
  1061.               if left(i) /= right(i) then return false; end if;
  1062.            end loop;
  1063.            return true;
  1064.         end string_eq;
  1065.  
  1066. The bug in this code is insidious because the routine works fine in most
  1067. cases.  It fails though when the right parameter is a slice such that
  1068. right'first /= left'first.  I think the principle of least surprise would
  1069. dictate that slice parameters be normalized similar to how they are in slice
  1070. assignment, although the unconstrained case doesn't apply for assignment.
  1071. This bug could easily bite anyone not sufficiently immunized from previous
  1072. bites.
  1073.  
  1074.  
  1075. Ada Programmer Errors                     6-Mar-86             20:03:24  14
  1076. 06.02(02)
  1077.  
  1078.  
  1079. *****************************************************************************
  1080.  
  1081. !section 06.02    (02)                                               ER-00041
  1082. !class NC
  1083. !topic Incorrect use of formal parameter modes
  1084.  
  1085. Pascal programmers seem to frequently write to an in-parameter and read from
  1086. an out-parameter, the error being to use them as local variables (especially
  1087. for an out-parameter).
  1088.  
  1089. *****************************************************************************
  1090.  
  1091. !section 06.02    (05)                                               ER-00062
  1092. !class UE
  1093. !topic Assignment to component designated by OUT parameter
  1094.  
  1095. If an OUT parameter has an access type, you are not allowed to assign to any
  1096. component of the designated object, since such an assignment requires that
  1097. the value of the OUT parameter be read, and the prefix of selected component
  1098. cannot be an OUT parameter having an access type [4.1(4)].
  1099.  
  1100. *****************************************************************************
  1101.  
  1102. !section 06.03                                                       ER-00001
  1103. !class BL
  1104. !topic ; instead of IS in subprogram bodies
  1105. !experience students
  1106.  
  1107. Error: using ";" instead of "IS" after procedure headers, especially
  1108.         on the heading of a file.
  1109.  
  1110. Reason for error: mostly a carry-over from Pascal and Modula-2.
  1111.  
  1112. Source of error: personal experience learning Ada.
  1113.  
  1114. Occurance: most likely by programmers still learning Ada.
  1115.  
  1116. Reason this is a problem: large number of fall-out error messages
  1117.         as the compiler then mis-interprets the entire block
  1118.         structure of the file.  The actual error is not even flagged.
  1119.  
  1120. *****************************************************************************
  1121.  
  1122. !section 06.03    (02)                                               ER-00051
  1123. !class BL
  1124. !topic Bodies that use IS rather than semicolon
  1125.  
  1126. Unhelpful diagnostic messages will usually appear when trying to compile a
  1127. procedure body where a semicolon has been used in place of the IS:
  1128.  
  1129.         with TEXT_IO; use TEXT_IO;
  1130.         procedure TEST;                 -- semicolon instead of IS
  1131.             package REAL_IO is new FLOAT_IO (FLOAT);
  1132.             use REAL_IO;
  1133.  
  1134. Ada Programmer Errors                     6-Mar-86             20:03:24  15
  1135. 06.03(02)
  1136.  
  1137.  
  1138.         begin ... end TEST;
  1139.  
  1140. *****************************************************************************
  1141.  
  1142. !section 06.03.01 (05)                                               ER-00056
  1143. !class NU
  1144. !topic can't omit IN in parameter decl if it is present in body
  1145.  
  1146. A formal parameter mode IN must be specified explicitly in both the
  1147. specification and body, or it must be left implicit in both places.
  1148.  
  1149. *****************************************************************************
  1150.  
  1151. !section 06.03.02 (04)                                               ER-00067
  1152. !class UE
  1153. !topic dependence on body due to INLINE
  1154.  
  1155. Although the use of pragma INLINE does not change the meaning of a program, it
  1156. can create a dependence on the body of the unit that is being inlined, i.e.,
  1157. after recompilation of an inlined body, an implementation can require that
  1158. units containing calls to the inlined unit also be recompiled.  This sort of
  1159. dependence on a body can only be imposed if the inlined unit and the calls are
  1160. compiled together in the same compilation file [10.3(7)].
  1161.  
  1162. *****************************************************************************
  1163.  
  1164. !section 06.06    (01)                                               ER-00061
  1165. !class NU
  1166. !topic Parameter names not considered in overloaded declarations
  1167.  
  1168. Consider
  1169.  
  1170.         subtype Switch1 is Positive range 1..10;
  1171.         subtype Switch2 is Positive range 1..25;
  1172.  
  1173.         procedure Set_Switch (First : Switch1);
  1174.         procedure Set_Switch (Second : Switch2);    -- illegal
  1175.  
  1176. The difference in parameter names does not suffice to allow the second
  1177. declaration as a legal overloading of the first.
  1178.  
  1179. *****************************************************************************
  1180.  
  1181. !section 08.03                                                       ER-00013
  1182. !class UE
  1183. !topic visibility rules for operators
  1184.  
  1185. I find that scoping rules for user defined types is an error prone "concept"
  1186. (as opposed to construct).  As you pointed out to me once before* according
  1187. to 8.3(18) an "operator is directly visible if and only if the corresponding
  1188. operator declaration is directly visible."  Yet, it is natural to write
  1189. something like the following (especially for 1st time users):
  1190.  
  1191.         package pack1 is
  1192.           type int is range 1..1000;
  1193.         end pack1;
  1194.  
  1195.  
  1196. Ada Programmer Errors                     6-Mar-86             20:03:24  16
  1197. 08.03
  1198.  
  1199.  
  1200.         with pack1;
  1201.         procedure demo is
  1202.           i: pack1.int := 5;
  1203.         begin
  1204.           .
  1205.           i := i+1;                     -- illegal
  1206.           .
  1207.           .
  1208.         end demo;
  1209.  
  1210. I realize that I could use a USE clause or RENAME the "+" operation, but I
  1211. feel that not using the full name in most situtations is less readable and
  1212. that both the USE clause & RENAMING are error prone (in fact 1 project here
  1213. has totally disallowed both) .  I would like to set up a project standard
  1214. where USE clause is only used for command package that are deemed acceptable
  1215. by project management (e.g., predefined packages and project global
  1216. definitions).  However, if I adopt such a standard I loose any benifit from
  1217. defining operators and in cases such as the one above I cannot use infixed
  1218. notation even for predefined operators, unless pack1 is one of my "acceptable"
  1219. packages.  On the other hand, If I allow the use of USE, but require that full
  1220. names be used (except maybe in specific situations), than I can no longer use
  1221. the compiler to enforce the full name requirement.
  1222.  
  1223. Unfortunately, I don't see a clean solution to this problem since redefine
  1224. the scope of an operator to be extended to the scope of the type(s) that it
  1225. operates on (for example) would be extremely difficult to define proprely
  1226. for operators that have parameters of different types.
  1227.  
  1228. *****************************************************************************
  1229.  
  1230. !section 08.03                                                       ER-00022
  1231. !class UE
  1232. !topic visibility of operators
  1233.  
  1234.         package P is
  1235.           type T is (T1, T2);
  1236.         end P;
  1237.  
  1238.         with P;
  1239.         procedure Main is
  1240.           V1, V2 : P.T;
  1241.         begin
  1242.           . . .
  1243.           if V1 = V2 then . . . end if;
  1244.         end Main;
  1245.  
  1246. One must explicitly import operations from another scope. Best solution is
  1247. to use a renames in the declarative region of Main:
  1248.  
  1249.         function "="(L, R : in P.T) return Boolean renames P."=";
  1250.  
  1251. One could also use a "use clause", expanded notation on P."=", or the Pos
  1252. attribute to convert V1 and V2 to universal_integers so that they could be
  1253.  
  1254. Ada Programmer Errors                     6-Mar-86             20:03:24  17
  1255. 08.03
  1256.  
  1257.  
  1258. compared for equality. All of these solutions are less than desirable.
  1259.  
  1260. *****************************************************************************
  1261.  
  1262. !section 08.03    (15)                                               ER-00071
  1263. !class UE
  1264. !topic Object declaration hides outer procedure declaration
  1265.  
  1266. Consider:
  1267.  
  1268.         with Text_IO; use Text_IO;
  1269.         procedure XYZ is
  1270.             New_Line : String(1..80);
  1271.  
  1272.             procedure ABC is
  1273.             begin
  1274.                 Put (" ... ");
  1275.                 New_Line;           -- illegal
  1276.             end ABC;
  1277.         ...
  1278.  
  1279. The call to New_Line is illegal since procedure New_Line is hidden by the
  1280. outer declaration of the variable New_Line.
  1281.  
  1282. *****************************************************************************
  1283.  
  1284. !section 08.03    (18)                                               ER-00055
  1285. !class UE
  1286. !topic Need a use clause to get visibility of operators
  1287.  
  1288. An attempt to use = or /= (or any other operator) for a type declared in a
  1289. library package will not work unless the package has been USEd:
  1290.  
  1291.         package Options_Utility is
  1292.             type Opt2_Values is (All1, Normal);
  1293.             function Opt2_Value (Option_On : Boolean) return Opt2_Values;
  1294.         end Options_Utility;
  1295.  
  1296.         with Options_Utility;
  1297.         procedure Tagging is
  1298.             subtype Opt2_Vals is Options_Utility.Opt2_Values;
  1299.             Options : Options_Utility.Opt2_Values := Opt2_Values.Normal;
  1300.         begin
  1301.             ...
  1302.             if Options_Utility.All1 /= Options then     -- illegal
  1303.  
  1304. The condition is illegal because the /= operator declared in Options_Utility
  1305. is not directly visible.  The subtype declaration does not make an operators
  1306. visible.
  1307.  
  1308.  
  1309. Ada Programmer Errors                     6-Mar-86             20:03:24  18
  1310. 08.04(05)
  1311.  
  1312.  
  1313. *****************************************************************************
  1314.  
  1315. !section 08.04    (05)                                               ER-00057
  1316. !class UE
  1317. !topic Conflict with a name declared in Standard
  1318.  
  1319. Consider
  1320.  
  1321.         package A is
  1322.             type Char_Type is (ASCII, EBCDIC);
  1323.         end A;
  1324.  
  1325.         use A;
  1326.  
  1327.         X : Char_Type := ASCII;         -- illegal!
  1328.  
  1329. Since ASCII is directly visible in STANDARD, the use clause for package A
  1330. does not make A.ASCII directly visible.  Since the declaration of X refers to
  1331. STANDARD.ASCII instead of A.ASCII, the expression is illegal.
  1332.  
  1333. *****************************************************************************
  1334.  
  1335. !section 08.04    (06)                                               ER-00053
  1336. !class UE
  1337. !topic Effect of USE on generic subprograms
  1338.  
  1339.         with TEXT_IO, INDEXED_MIXED_IO;
  1340.         use TEXT_IO, INDEXED_MIXED_IO;
  1341.         procedure BUG is
  1342.         begin
  1343.             PUT("Testing");             -- undeclared PUT
  1344.         end BUG;
  1345.  
  1346. INDEXED_MIXED_IO contains a declaration of PUT as a generic procedure.  The
  1347. presence of this non-overloadable declaration means none of the declarations
  1348. of PUT in TEXT_IO or INDEXED_MIXED_IO are made directly visible.
  1349.  
  1350. As a design issue, this suggests that a generic unit should never be given
  1351. the same name as a non-generic unit in another package, if the two are likely
  1352. to be USEd together.
  1353.  
  1354. *****************************************************************************
  1355.  
  1356. !section 08.04    (06)                                               ER-00066
  1357. !class UE
  1358. !topic Use clause and renamed exceptions
  1359.  
  1360. Consider
  1361.  
  1362.         package Math_Exceptions is
  1363.             Negative_Argument : exception;
  1364.         end;
  1365.  
  1366.         with Math_Exceptions;
  1367.         package Math_1 is
  1368.  
  1369. Ada Programmer Errors                     6-Mar-86             20:03:24  19
  1370. 08.04(06)
  1371.  
  1372.  
  1373.             Negative_Argument : exception
  1374.                 renames Math_Exceptions.Negative_argument;
  1375.  
  1376.         end;
  1377.  
  1378.         package Math_2 is
  1379.             Negative_Argument : exception
  1380.                 renames Math_Exceptions.Negative_argument;
  1381.         end;
  1382.  
  1383.         with Math_1; use Math_1;
  1384.         with Math_2; use Math_2;
  1385.         procedure Check is
  1386.         begin
  1387.             null;
  1388.         exception
  1389.             when Negative_Argument => ...   -- illegal
  1390.  
  1391. Negative_Argument is not visible because exceptions are not overloadable and
  1392. the declarations in both Math_1 and Math_2 mean the use clauses do not make
  1393. the declarations of Negative_Argument visible.  It is immaterial that both
  1394. declarations denote the same exception.
  1395.  
  1396. *****************************************************************************
  1397.  
  1398. !section 08.05                                                       ER-00017
  1399. !class NU
  1400. !topic renaming task entries
  1401.  
  1402. On trying to "hide" tasks in a package body:
  1403.  
  1404.         package P is
  1405.           procedure I_Am_Trying_to_be_a_Task_Entry;
  1406.         end P;
  1407.         package body P is
  1408.           task T is
  1409.             entry E;
  1410.           end T;
  1411.           task body T is
  1412.           begin
  1413.             accept E;
  1414.           end;
  1415.           procedure I_Am_Trying_to_be_a_Task_Entry renames T.E;
  1416.         end P;
  1417.  
  1418. One solution to this problem (albeit not the best one) is:
  1419.  
  1420.           package P is . . . end P;
  1421.           package body P is
  1422.             . . .
  1423.             procedure I_Am_Trying_to_be_a_Task_Entry is
  1424.             begin
  1425.               T.E;
  1426.  
  1427. Ada Programmer Errors                     6-Mar-86             20:03:24  20
  1428. 08.05
  1429.  
  1430.  
  1431.             end;
  1432.           end P;
  1433.  
  1434. *****************************************************************************
  1435.  
  1436. !section 08.05                                                       ER-00027
  1437. !class UE
  1438. !topic ignoring constraints in renaming
  1439.  
  1440.         procedure P is
  1441.           A : Integer;
  1442.           B : Positive renames A;
  1443.           C : Positive;
  1444.           D : Integer renames C;
  1445.         begin
  1446.           B := -10;
  1447.           D := B;
  1448.         end P;
  1449.  
  1450. Obviously, the user doesn't understand that constraints implied by a type mark
  1451. on a renaming are ignored and the constraints are that of the actual.
  1452. Constraint_Error will be raised during the attempt to assign B to D.
  1453.  
  1454. *****************************************************************************
  1455.  
  1456. !section 09.0                                                        ER-00084
  1457. !class UE
  1458. !topic Deadlock because of exception propagation
  1459.  
  1460. If during the execution of a task, an unexpected exception is raised and is
  1461. propagated to the task body and not handled, the task is terminated silently.
  1462. Any tasks that are waiting for calls from this terminated task will wait
  1463. forever at an accept statement unless the statement has a terminate
  1464. alternative.  This source of deadlock can be very difficult to locate unless
  1465. the Ada debugger notes that a particular task terminated because of an
  1466. unhandled exception.
  1467.  
  1468. Another subtle way to get deadlock is by attempting to propagate an exception
  1469. out of a frame that has dependent tasks:
  1470.  
  1471.         procedure P is
  1472.             task T is
  1473.                 entry E;
  1474.             end T;
  1475.  
  1476.             task body T is ... end T;
  1477.         begin
  1478.             ... some statement raising an exception unexpectedly
  1479.             T.E;
  1480.         end P;
  1481.  
  1482. Control cannot leave P until dependent task T is terminated, but the task
  1483. cannot terminate because it is waiting for the entry call T.E, which will
  1484. never be executed because of the exception.
  1485.  
  1486.  
  1487. Ada Programmer Errors                     6-Mar-86             20:03:24  21
  1488. 09.0
  1489.  
  1490.  
  1491. *****************************************************************************
  1492.  
  1493. !section 09.01    (04)                                               ER-00079
  1494. !class UE
  1495. !topic Can't use task type name in its own body
  1496.  
  1497. One way to look for solutions is to dispatch tasks to look for solutions to
  1498. subproblems.  Each task might want to in turn, dispatch copies of itself to
  1499. explore a smaller portion of the solution space.  Such programs tend to have a
  1500. structure like the following:
  1501.  
  1502.         package Search is
  1503.  
  1504.             task type Seeker is
  1505.                 ...
  1506.             end Seeker;
  1507.  
  1508.             type filter is access Seeker;
  1509.  
  1510.         end Search;
  1511.  
  1512.         package body Search is
  1513.  
  1514.             task body Seeker is
  1515.             begin
  1516.                 ... -- dispatch new seeker
  1517.                 new_filter := new Seeker;   -- illegal
  1518.             end Seeker;
  1519.  
  1520.         end Search;
  1521.  
  1522. The allocator is illegal within the body of Seeker because the name Seeker
  1523. cannot be used as a type mark within the body.
  1524.  
  1525. To get around this rule, declare a subtype in the package body, just before
  1526. the task body:
  1527.  
  1528.             subtype Seeker_Type is Seeker;
  1529.  
  1530. and then use the subtype name to activate the new copy of the task:
  1531.  
  1532.             ... new_filter := new Seeker_Type;  -- ok now
  1533.  
  1534. *****************************************************************************
  1535.  
  1536. !section 09.02                                                       ER-00087
  1537. !class UE
  1538. !topic Use task types instead of single tasks
  1539.  
  1540. The amount of storage provided for a task can be specified with a
  1541. representation clause only if a task type is used.  To preserve flexibility,
  1542. it is best to use task types instead of single task declarations.
  1543.  
  1544.  
  1545. Ada Programmer Errors                     6-Mar-86             20:03:24  22
  1546. 09.04
  1547.  
  1548.  
  1549. *****************************************************************************
  1550.  
  1551. !section 09.04                                                       ER-00034
  1552. !class UE
  1553. !topic Nested task termination and leaving block
  1554.  
  1555.         procedure Main is
  1556.           task T is
  1557.             entry E(. . .);
  1558.           end T;
  1559.           task body T is
  1560.           begin
  1561.             loop
  1562.               accept E(. . .) do ... end E;
  1563.             end loop;
  1564.           end T;
  1565.         begin
  1566.           while <condition> loop
  1567.             . . .
  1568.             T.E(. . .);
  1569.              . . .
  1570.           end loop;
  1571.         end Main;
  1572.  
  1573. Many programmers don't realize that task T causes termination problems. The
  1574. accept statement in task T can be replaced by the following select statement
  1575. to provide the desired semantics and thus eliminate the termination problems:
  1576.  
  1577.           select
  1578.             accept E(. . .) do . . . end E;
  1579.           or
  1580.             terminate;
  1581.           end select;
  1582.  
  1583. *****************************************************************************
  1584.  
  1585. !section 09.04    (13)                                               ER-00048
  1586. !class UE
  1587. !topic Termination of library tasks
  1588.  
  1589. If a library task does not terminate normally, it should wait at a select
  1590. statement with a terminate alternative, so the library task can be terminated
  1591. when the main program is complete and all library tasks are inactive.
  1592. Programmers sometimes fail to include the terminate alternative, so their
  1593. programs appear to hang (in fact, the programs are deadlocked, because a
  1594. library task is waiting at a select statement that will never be executed).
  1595.  
  1596. *****************************************************************************
  1597.  
  1598. !section 09.05                                                       ER-00085
  1599. !class UE
  1600. !topic deadlock by mismatched entry indexes
  1601.  
  1602. Deadlock can easily occur when calling entry families if the entry family
  1603. indexes are mismatched:
  1604.  
  1605.  
  1606. Ada Programmer Errors                     6-Mar-86             20:03:24  23
  1607. 09.05
  1608.  
  1609.  
  1610.         T.Some_Family (2);      -- entry family index 2
  1611.  
  1612. and the accept statement currently being executed is
  1613.  
  1614.         accept Some_Family (3);
  1615.  
  1616. Although this case is easy to see, it's not so easy when the indexes are
  1617. specified with expressions whose value is determined at run time.
  1618.  
  1619. *****************************************************************************
  1620.  
  1621. !section 09.06                                                       ER-00019
  1622. !class UE
  1623. !topic delay 2.5*minutes is illegal
  1624.  
  1625.         Minutes : constant DURATION := 60.0;
  1626.          . . .
  1627.         delay 2.5 * Minutes;
  1628.  
  1629. This is the old "result is universal_fixed" problem. Two solutions are:
  1630.  
  1631.         -- make "Minutes" an Integer type equal to 60
  1632.         -- used explicit type conversion on the result of the delay expression
  1633.  
  1634. *****************************************************************************
  1635.  
  1636. !section 09.06    (01)                                               ER-00047
  1637. !class UE
  1638. !topic Delay statments can be used in the main program
  1639.  
  1640. Programmers have been observed to use loops of various kinds to delay
  1641. progress of the main program instead of a delay statement, apparently in the
  1642. belief that a delay statement can only be used in a task body.  But the delay
  1643. statement can be used in a main program as well as in a user-defined task.
  1644.  
  1645. *****************************************************************************
  1646.  
  1647. !section 09.07.01                                                    ER-00003
  1648. !class UC
  1649. !topic evaluation of guards
  1650.  
  1651. I think the area which seem to be the most error prone in Ada is the
  1652. processing of guards in conditional selects.  Both Ichbiah and Barnes have
  1653. published programs that will not work because they assumed the guards and the
  1654. entry calls are atomic or tasks don't abort.
  1655.  
  1656. *****************************************************************************
  1657.  
  1658. !section 09.07.01 (06)                                               ER-00086
  1659. !class UE
  1660. !topic "fairness" is not guaranteed
  1661.  
  1662. Programmers using selective waits with several open alternatives can easily
  1663. make unconscious assumptions that the alternatives will be servied fairly,
  1664. i.e., in a way such that no alternative is starved for service, but the
  1665. Standard does not require fair service, and some implementations do not go to
  1666.  
  1667. Ada Programmer Errors                     6-Mar-86             20:03:24  24
  1668. 09.07.01(06)
  1669.  
  1670.  
  1671. the trouble to provide it.
  1672.  
  1673. *****************************************************************************
  1674.  
  1675. !section 09.10                                                       ER-00088
  1676. !class UE
  1677. !topic delay 0.0 can synchronize an abort
  1678.  
  1679. Since an abort must occur no later than a synchronization point, and since a
  1680. delay statement is a synchronization point, it is sometimes useful to write
  1681.  
  1682.         delay 0.0;
  1683.  
  1684. in a task that might be aborted to ensure the abortion occurs no later than a
  1685. particular point in the code.
  1686.  
  1687. *****************************************************************************
  1688.  
  1689. !section 10.01    (06)                                               ER-00072
  1690. !class UE
  1691. !topic recompiling a library subprogram body
  1692.  
  1693. Suppose a library is initially empty and one compiles:
  1694.  
  1695.         procedure LIB is        -- this is the library unit
  1696.             ...
  1697.         end LIB;
  1698.  
  1699.         with LIB;
  1700.         procedure X is
  1701.             ...
  1702.         end X;
  1703.  
  1704. The procedure LIB is considered a library unit.  Its recompilation causes
  1705. procedure X to become obsolete, because X references library unit LIB.
  1706. On the other hand, suppose the initial compilation sequence had been:
  1707.  
  1708.         procedure LIB;          -- this is the library unit
  1709.  
  1710.         procedure LIB is        -- secondary unit
  1711.             ...
  1712.         end LIB;
  1713.  
  1714.         with LIB;
  1715.         procedure X is
  1716.             ...
  1717.         end X;
  1718.  
  1719. Now recompilation of LIB's body does not cause X to become obsolete because
  1720. the body is not itself a library unit.
  1721.  
  1722.  
  1723. Ada Programmer Errors                     6-Mar-86             20:03:24  25
  1724. 10.01.01
  1725.  
  1726.  
  1727. *****************************************************************************
  1728.  
  1729. !section 10.01.01                                                    ER-00002
  1730. !class NC
  1731. !topic A with clause is not like an Include
  1732. !experience students
  1733.  
  1734.         with text_io; use text_io;
  1735.         package int_io is new integer_io(integer);
  1736.         with int_io; use int_io;
  1737.         with text_io; use text_io; -- this line  gets forgotten because "I
  1738.                                    -- defined it once!"
  1739.         procedure foo is
  1740.           answer: constant integer := 42;
  1741.           begin
  1742.            put (answer);
  1743.            put_line (" is the answer");
  1744.           end;
  1745.  
  1746. This has been made by Pascal programmers who think of the with facility as an
  1747. include whose scope is the entire source file.
  1748.  
  1749. *****************************************************************************
  1750.  
  1751. !section 10.01.01                                                    ER-00012
  1752. !class NC
  1753. !topic confusion of with and use
  1754.  
  1755. Pascal programmers confuse the effects of with and use clause
  1756.  
  1757. *****************************************************************************
  1758.  
  1759. !section 10.02                                                       ER-00011
  1760. !class BL
  1761. !topic Spelling SEPARATE correctly
  1762.  
  1763. Programmers have complained about not remembering how to spell 'separate'.
  1764.  
  1765. *****************************************************************************
  1766.  
  1767. !section 10.02    (05)                                               ER-00050
  1768. !class BL
  1769. !topic Overloaded subunits are illegal
  1770.  
  1771.         procedure foo is
  1772.                 procedure A (X : INTEGER) is separate;
  1773.                 procedure A (X : FLOAT) is separate;    -- illegal
  1774.         begin ... end;
  1775.  
  1776. Although the declarations of A as overloaded procedures are legal, subunit
  1777. names must be distinct.
  1778.  
  1779. This problem has been reported twice.
  1780.  
  1781.  
  1782. Ada Programmer Errors                     6-Mar-86             20:03:24  26
  1783. 10.02(05)
  1784.  
  1785.  
  1786. *****************************************************************************
  1787.  
  1788. !section 10.02    (05)                                               ER-00064
  1789. !class BL
  1790. !topic Subunits cannot be operators
  1791.  
  1792.         function "<" (L, R : A_Type) return Boolean is separate;
  1793.  
  1794. is illegal because subunit names must be identifiers.
  1795.  
  1796. *****************************************************************************
  1797.  
  1798. !section 10.05    (03)                                               ER-00069
  1799. !class UE
  1800. !topic Failure to use pragma ELABORATE for generic units
  1801.  
  1802. When a generic library unit is instantiated inside a library unit or secondary
  1803. unit, a pragma ELABORATE must be used to ensure the generic unit body is
  1804. elaborated before the instantiation.  For example,
  1805.  
  1806.         package P is
  1807.             ...
  1808.         end P;
  1809.  
  1810.         with Sequential_IO;
  1811.         package body P is
  1812.             package Char_IO is new Sequential_IO (Character);
  1813.             ...
  1814.         end P;
  1815.  
  1816.         with P;
  1817.         procedure MAIN is
  1818.             ...
  1819.         end MAIN;
  1820.  
  1821. PROGRAM_ERROR can be raised when an attempt is made to execute MAIN; when the
  1822. instantiation of Sequential_IO is elaborated, it is not guaranteed that the
  1823. body of Sequential_IO will have been elaborated.
  1824.  
  1825. The situation is different for a main program:
  1826.  
  1827.         with Sequential_IO;
  1828.         procedure MAIN2 is
  1829.             package Char_IO is new Sequential_IO (Character);
  1830.             ...
  1831.         end MAIN2;
  1832.  
  1833. No PROGRAM_ERROR will be raised here because all library units and their
  1834. bodies must be elaborated before execution of the main program.
  1835.  
  1836. This problem has been reported independently four or five times.
  1837.  
  1838.  
  1839. Ada Programmer Errors                     6-Mar-86             20:03:24  27
  1840. 11.04.02
  1841.  
  1842.  
  1843. *****************************************************************************
  1844.  
  1845. !section 11.04.02                                                    ER-00035
  1846. !class UE
  1847. !topic Handling exceptions raised in declarations
  1848.  
  1849.         procedure Main
  1850.           I : POSITIVE := 0;
  1851.         begin
  1852.           . . .
  1853.         exception
  1854.           when CONSTRAINT_ERROR => -- for I's declaration
  1855.             . . .
  1856.         end Main;
  1857.  
  1858. The exception handler won't catch CONSTRAINT_ERROR for the elaboration of I.
  1859. Exception handlers do not catch exceptions originating from a declarative
  1860. region outside of their scope.
  1861.  
  1862. *****************************************************************************
  1863.  
  1864. !section 12.01                                                       ER-00029
  1865. !class NU
  1866. !topic No out mode for generic formal objects
  1867.  
  1868.         generic
  1869.           I : out INTEGER;
  1870.         package P is ... end P;
  1871.  
  1872. Cannot have a mode "out" generic formal object.
  1873.  
  1874. *****************************************************************************
  1875.  
  1876. !section 12.01                                                       ER-00032
  1877. !class NU
  1878. !topic no overloaded generic units
  1879.  
  1880.         package P is
  1881.           generic
  1882.             with function F return INTEGER;
  1883.           procedure P(X : INTEGER);
  1884.           . . .
  1885.           generic
  1886.             with function F return INTEGER;
  1887.           procedure P(Y : FLOAT);
  1888.           . . .
  1889.         end P;
  1890.  
  1891. Many programmers thought that the two generics could be overloaded properly
  1892. since they thought they could be distinguished by procedure P's formal
  1893. parameter list. Of course, this is not true, and the two generic are
  1894. homographs.
  1895.  
  1896.  
  1897. Ada Programmer Errors                     6-Mar-86             20:03:24  28
  1898. 12.01
  1899.  
  1900.  
  1901. *****************************************************************************
  1902.  
  1903. !section 12.01                                                       ER-00075
  1904. !class NC
  1905. !topic Generics are not macros
  1906.  
  1907. A programmer had three record types that each contained a name field.  He
  1908. wanted to make a linked list generic package that would use the name field as
  1909. a key for searching.  He planned to instantiate the package with the record
  1910. type but then use the dot notation to access the name component.  Although he
  1911. knew that the record type was defined elsewhere and could be accessed there,
  1912. he also thought that he should be able to access components within the generic
  1913. package.  After all, it was private but in the package specification.  The
  1914. compiler flags this, of course, and he tried a number of strange things before
  1915. coming to me and saying that the compiler was wrong.  It took two discussions
  1916. of at least half an hour each to get him to understand the difference between
  1917. the privacy of generic formal private types and regular private types.
  1918.  
  1919. This I think shows the person is thinking of generic units as a kind of macro
  1920. whose meaning and legality is determined only when it is instantiated.
  1921. Certainly the above approach would have worked if generics were treated like
  1922. macros.
  1923.  
  1924. *****************************************************************************
  1925.  
  1926. !section 12.01    (02)                                               ER-00081
  1927. !class NU
  1928. !topic generic subprograms bodies can't be delared with generic parameters
  1929.  
  1930. Although one generally has the choice of providing an explicit subprogram
  1931. declaration or just a subprogram body, this is not true for generic
  1932. subprograms:
  1933.  
  1934.         generic
  1935.             type T is private;
  1936.         procedure P is          -- illegal
  1937.         begin ... end;
  1938.  
  1939. The generic body cannot have generic formal parameters.
  1940.  
  1941. *****************************************************************************
  1942.  
  1943. !section 14.03                                                       ER-00028
  1944. !class UE
  1945. !topic I/O calls in tasks
  1946.  
  1947. The part of Ada that continuously gives me and others a hard time is text_io.
  1948. Last Friday 3 of us wasted an hour until we concluded that text_io is a single
  1949. thread package and cannot support simultaneous calls to get and put (one in
  1950. each of two tasks). In the recent past I have had difficulty with while loops
  1951. which look for EOF and doing a get in the loop.
  1952.  
  1953.  
  1954. Ada Programmer Errors                     6-Mar-86             20:03:24  29
  1955. 14.03
  1956.  
  1957.  
  1958. *****************************************************************************
  1959.  
  1960. !section 14.03                                                       ER-00065
  1961. !class UE
  1962. !topic Associating two file variables with a terminal
  1963.  
  1964. The line and column numbers for files are kept independently for file
  1965. variables.  If two file variables are associated with a single physical
  1966. device, programmers should not assume that, for example, writing to one of
  1967. the file objects will update the line and column count for the other file
  1968. object.
  1969.  
  1970. *****************************************************************************
  1971.  
  1972. !section 14.03.05 (03)                                               ER-00046
  1973. !class UE
  1974. !topic PUT at the end of the program
  1975.  
  1976. An implementation is allowed to buffer characters whose output is requested
  1977. by PUT.  In particular, the characters might not be transferred to an output
  1978. device until a NEW_LINE request is given (either explicitly or implicitly as
  1979. a result of a call to PUT_LINE, SKIP_LINE, etc.), or until the number of
  1980. buffer characters exceeds some implementation-defined maximum.
  1981.  
  1982. It is implementation-dependent whether or not a partially filled buffer will
  1983. be flushed to a file (or output device) when the main program finishes.
  1984.  
  1985. *****************************************************************************
  1986.  
  1987. !section 14.03.06 (03)                                               ER-00074
  1988. !class UE
  1989. !topic GET for chars skips line terminators
  1990.  
  1991. *****************************************************************************
  1992.  
  1993. !section 14.03.07 (06)                                               ER-00052
  1994. !class UE
  1995. !topic Failing to advance after DATA_ERROR for INTEGER GET
  1996.  
  1997. An attempt to read a real literal, e.g., 3.4, with integer GET does not
  1998. produce any error indication for the first read attempt (which has the effect
  1999. of reading in the integer part of the literal).  A subsequent read will raise
  2000. DATA_ERROR, because the first character to be read will be a period.  But
  2001. users tend to think the entire numeric literal should have been read, with
  2002. DATA_ERROR being raised because of the embedded decimal point.
  2003.  
  2004. *****************************************************************************
  2005.  
  2006. !section 14.03.09 (06)                                               ER-00063
  2007. !class UE
  2008. !topic Failing to advance after DATA_ERROR for ENUM GET
  2009.  
  2010. Consider the effect of reading the following characters with GET for an
  2011. enumeration type:
  2012.  
  2013.         XXX 2 YYY
  2014.  
  2015.  
  2016. Ada Programmer Errors                     6-Mar-86             20:03:24  30
  2017. 14.03.09(06)
  2018.  
  2019.  
  2020. Suppose neither XXX nor YYY are values of the type.  The first GET reads XXX
  2021. since XXX satisfies the syntax for an enumeration literal, and stops at the
  2022. blank.  The second GET reads over the blank and then stops at the 2, since
  2023. an identifier cannot begin with a digit.  A third GET starts to read with the
  2024. digit 2, since this is where reading stopped previously.  Subsequent GETs
  2025. will not advance the position in the file.
  2026.  
  2027.  
  2028.  
  2029.