In / Out vs Out in Ada

I have a quick question from Ada. If I have a procedure in which I can write a variable, or I can leave it alone, should it be a parameter Outor In Out? I think it comes down to the question:

What the caller sees is he calling a procedure with a parameter Out, but the procedure does not concern the parameter. Does he see the same meaning? Undefined behavior?

The compiler does not complain because it sees the purpose of the variable Out... it is just in a conditional expression where it cannot be reached, and the compiler does not bother to check all the paths.

I suspect that a safe bet indicates the parameter as In Out, but I would like to know if this is necessary or just stylistically preferable.

Thank!

-prelic

+5
source share
1 answer

In Ada, when a procedure with a parameter outwrites nothing to this parameter, the result passed back to the caller is something undefined. This means that everything that was in this variable in the caller is overwritten by garbage when it returns from the procedure.

Best practice in Ada is to finalize all parameters outwith the appropriate default value at the beginning of the procedure. Thus, any code path from the procedure results in valid data passed back to the caller.

If you have something in the caller that can be changed using the procedure, you should use the parameter in out.

From Ada 95 RM 6.4.1 (15) :

. , ( Constraint_Error), - . , .

+11

All Articles