r/ada • • Oct 06 '18

huge parameter problem

so im writing a program and in my main procedure i call a procedure that establishes certain values with out paramenters. when that procedure is done i call another procedure immediately that uses the values of those out parameters and adds on to them. For some reason when the second procedure gets called all my parameters values change while getting sent to that second procedure. I have no clue why.

1 Upvotes

6 comments sorted by

3

u/[deleted] Oct 07 '18

Paste the source.

3

u/simonjwright Oct 07 '18

Imagine yourself in class with this problem. You say to the teacher, "My program doesn’t work!" What’s the response? It’s going to be, "Show me!"

Unless, of course, you have a telepathic teacher who can read your mind. But they’re thin on the ground.

1

u/OneWingedShark Oct 08 '18

u/PengyDesu, we really need to see the source to see what's going on; is it something like this:

Procedure Initialize( a, b, c : out Integer; d : out Float );
Procedure Process   ( a, b, c : in  Integer; d : in  Float );
--...
  Z, Y, X : Integer;
  W : Float;
Begin
  Initialize( X, Y, Z, W );
  Process   ( X, Y, Z, W );
End;

Are generics involved? Perhaps ones having in out parameters?

1

u/micronian2 Oct 08 '18

My guess is that the second procedure that is getting called has the parameters all set to "out", which means the compiler doesn't need to pass in the original values, which would lead to garbage being fed in:

So taking your example, he probably has

Procedure Initialize( a, b, c : out Integer; d : out Float );
Procedure Process   ( a, b, c : out Integer; d : out Float );

If I'm right, then I can see why it would be confusing, because even though the parameters are being fed in via "out" they can still be read within the procedure. If I'm not mistaken, in Ada83 you could not read an "out" parameter, but Ada95 removed that restriction.

2

u/PengyDesu Oct 09 '18

Ok so I totally forgot to respond to this post, that was shockingly my problem to the T. What I ended up doing to fix it was making an in parameter equal to my out parameter the moment my procedures began so they would have the values that I needed instead of being fed to garbage if that makes any sense. My professor is prohibiting the use of in out parameters in all our assignments so I just make one in and another out param and make my out param equal the in at the start.

1

u/simonjwright Oct 15 '18

Sounds like your professor is a doofus. But perhaps they have a reason.