Inconsistent argument passing mode
ada
Solution
You’ll have received a warning on the `Sub_Proc(N);` call: `"N" may be referenced before it has a value`. So the compiler was trying to help!
In Ada 83, your program would have been illegal: 6.4.1(3) says "for the mode in out, the variable must not be a formal parameter of mode out”. Indeed, using `-gnat83`, and after a minor rearrangement of the code to allow it to compile, the equivalent to the above warning is the error `(Ada 83) illegal reading of out parameter`.
In Ada 95 and Ada 2012 it is OK to read the value of an `out` parameter after it has been assigned; in ARM95 6.4.1(15) we find that the value starts out uninitialized (as indicated by the warning message noted above), so using it is a Bad Idea.
So the answer is, GNAT’s behaviour conforms with the standard.
Problem
Consider the following code (which compile with GCC 4.7.4): ``` procedure Main is procedure Sub_Proc(N : in out Integer) is M : Integer; begin M := N; end; procedure Proc(N : out Integer) is begin Sub_Proc(N); end; N : Integer; begin Proc(N); end Main; ``` The procedure `Proc` is supposed to ensure that the argument `N` which is an out argument will never be read inside his body. But it passes this argument to a procedure `Sub_Proc` which takes an in out argument, so potentially the previous argument will be read inside this procedure whereas the calling procedure ensured the opposite. Is it a GCC bug or an Ada standard specificity ?