No announcement yet.

Declaring Arrays as Function Parameters

  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    Using the internal function ArrayInfo&, you can pass ANY type of array to a procedure, get its type and your procedure can act accordingly.

    You have to call the procedure passing the address of the array descriptor, as in...
     DIM pDescriptor AS DWORD
      pDescriptor = VARPTR32 (array())
    FUNCTION PlayWithArray (BYVAL dAddr AS DWORD)
    ' use ArrayInfo& here to get the type of data in the array.
    ArrayInfo& is documented in the PB/DOS help file under 'internal functions'.

    (It is also not available in PB/Windows, a real shame)

    If you need a more complete sample, let me know. I have some code I will send you or if I'm in a good mood I'll post it in the source code forum.

    Michael Mattias
    Racine WI USA
    [email protected]

    Leave a comment:

  • Andrew Burt
    Guest replied
    Thanks for your response. The use of MIN|MAX in a DIM statement
    makes sense. What is muddying the water a bit is the way that
    the Reference Guide shows that array parameters for functions
    must be declared using MIN|MAX (page 128). Theoretically,
    several difference arrays may be passed to the same function in
    various places in a program and these arrays don't always have
    to have the same upper and lower bounds. Having to specify in
    the function prototype if the array's lower bound is zero could
    present problems.


    Leave a comment:

  • Lance Edmonds
    Generally this strategy is used in PBU code, rather than in the main code. Additionally, the MIN/MAX keywords are used in the DIM statement, not the sub/function prototype.

    Anyway, here is a brief example of the usage. See page 92 in the Refernce Guide for a description of the differences between MIN and MAX in a DIM statement.
    DIM a(100:200) AS SHARED LONG
    CALL mysub
    PRINT a(100), a(200)
    SUB MySub
     PRINT LBOUND(a(1)), UBOUND(a(1))
     a(100) = 1
     a(200) = 2
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Andrew Burt
    Guest started a topic Declaring Arrays as Function Parameters

    Declaring Arrays as Function Parameters

    Can someone please clarify the purpose of MIN and MAX
    when declaring array parameters in a Function? I've used VB and
    QB extensively in the past and the use of MIN and MAX seems a
    bit alien to me.

    Is its use optional? For instance, if I have an array declared
    as below:

    DIM MyList(1 TO 30) AS INTEGER

    Can I define my function as follows:

    DECLARE FindAverage (TheList())
    FUNCTION FindAverage TheList() AS INTEGER

    or must I define the function as:

    FUNCTION FindAverage TheList(MIN, 1) AS INTEGER