Computer Science Canada Making an Array fit into a Procedure Nice and Snug |
Author: | Bacchus [ Thu Jun 09, 2005 9:11 pm ] | ||
Post subject: | Making an Array fit into a Procedure Nice and Snug | ||
Ok, my problem is I want to know if theres a way to make a procedure accept the lower bounds of an array. Ex)
|
Author: | lyam_kaskade [ Thu Jun 09, 2005 9:48 pm ] | ||
Post subject: | |||
Hmmm...you could try something like
Although to me that seems needlessly complicated somehow. Best I can think of for now though. Maybe something with a flexible array would work... EDIT: Furthermore, I found this in the reference: Quote: In the declaration of an array parameter, the upper bound can be given as an asterisk (*), as is done in the above example. and Quote: Since the lower bound is necessarily known at compile time, lower is rarely used. The first thing doesn't mention lower bound at all, and the second thing says "necessarily". Err...if that helps. |
Author: | Bacchus [ Thu Jun 09, 2005 10:05 pm ] |
Post subject: | |
Ya I know, but have you also tested your code there? I tried many things before including one similar to that. What I found was that it gives you an error when you try to put an array with the lower bounds that are different than the lower bounds in the parameter's array. Also with your code, I got the error: "'lower' cannot have subscripts" |
Author: | lyam_kaskade [ Thu Jun 09, 2005 10:13 pm ] |
Post subject: | |
Oops...yeah the "lower" parameter should have a different name, because that's a keyword. It gets rid of the subscript problem, but it still say compile time expression expected, so that's a bust. I guess there's no way that I know of to do it. Sorry. |
Author: | Delos [ Fri Jun 10, 2005 9:24 am ] |
Post subject: | |
The lower bound of an array must be known at compile time. There's nothing more to it. I'm not sure why'd you want to have an array that starts and ends at variable positions - you could just use a flexible array... This, IMHO, is actually a good thing, since it reduces the possibility of creating a situation where the bounds of the array get confused needlessly. |
Author: | Bacchus [ Fri Jun 10, 2005 11:37 pm ] |
Post subject: | |
The problem was if I wanted to Import the array into a procedure through the procedures parameters. But I guess I must hard-code the procedure and array. |
Author: | jamonathin [ Sat Jun 11, 2005 6:58 am ] | ||
Post subject: | |||
Why dont you cheat. Im not using turing right now so it may not work, but here
Just having something represnt the lower(foo)? |
Author: | Cervantes [ Sat Jun 11, 2005 8:00 am ] | ||
Post subject: | |||
That does not work. It only works if the lower bounds of both the actual and the formal parameters are the same. I was thinking you could do something like this, but it doesn't work. I'll post it anyways, in case it gives anyone a brainstorm:
This assumes that your array will never have a lower bounds less than zero. But, it also does not work. Hopefully someone can extend it, because I'm stuck. |
Author: | jamonathin [ Sat Jun 11, 2005 5:42 pm ] | ||||
Post subject: | |||||
But what if we were to change it so that . . .
Unless you can var an array into the negatives, such as.
I've never tried it, and i can barely think of any scenerio's where it would make sense, if any. |