Computer Science Canada

pass arrays to modules?

Author:  Clayton [ Mon Apr 10, 2006 6:14 pm ]
Post subject:  pass arrays to modules?

hey, just wondering, is it possible to pass entire arrays to a module and have that module return the array (ex. in a sorting module). if its possible could u plz let me know how thnx

Author:  [Gandalf] [ Mon Apr 10, 2006 6:18 pm ]
Post subject: 

Hmm? Unless I mistake your question, of course.

Modules are able to include procedures and functions which are in turn able to accept arrays as arguments.

Author:  Clayton [ Mon Apr 10, 2006 6:20 pm ]
Post subject: 

but how would you pass the array from a main program to a module without splitting an array up into different pieces (ex. 1 piece of info at a time)

Author:  [Gandalf] [ Mon Apr 10, 2006 6:26 pm ]
Post subject: 

The same way you would pass an array to a procedure or function:
code:
var myGlobalArray : array 1 .. 3 of int := init (3, 4, 6)
proc putArray (localArray : array 1 .. * of int)
    for i : 1 .. upper (localArray)
        put localArray(i)
    end for
end putArray
putArray(myGlobalArray)

It works the same for a procedure in a module.

Author:  Clayton [ Mon Apr 10, 2006 6:44 pm ]
Post subject: 

oh ok thnx alot, talk about a brain fart lol


: