tags:

views:

103

answers:

1

how to swap two integer number in ada83 using pass by address

A: 

As far as I know, Ada does not let you specify what method the parameters are passed with; rather, you specify parameters as being either in, out, or in out and then the compiler will decide what the most efficient parameter passing method is.

So, to swap 2 numbers, you will have to (at the least) declare the parameters as out, since you want the swapped values to be visible in the formal paramaters (the variables in the original calling code). However, you will also need to set the parameters as in, since you will need to copy / move the variables in your function body.

Finally, the actual code itself - this is quite simple to do. You merely need to create a temporary variable, copy the contents of the first variable into your temporary variable, move the second variable into the first, and then move the temporary variable's contents into the second variable.

Hopefully that is a helpful answer to anyone else attempting this.

a_m0d