Announcement

Collapse
No announcement yet.

CDECL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CDECL

    Is there a way, other than using COMMON, SHARED, or PUBLIC, to pass an array as an optional parameter to a CDECL procedure?

    The users manual and reference manual do not mention that arrays can or cannot be passed as an optional parameter, just that optional parameters can be passed. Nor do they mention that the optional parameters cannot have AS type statements attached to them.

    [This message has been edited by Walt Decker (edited April 21, 2000).]
    Walt Decker

  • #2
    The CDECL parameter passing option doesn't seem to support passing
    arrays as optional parameters, as you noted. Probably the only way
    you will be able to pass array data to your SUBs as optional
    parameters will be to pass pointers to the arrays (CDECL SUBs support
    passing arrays as long as they're not optional parameters). Actually,
    its easier to just pass an address as a DWORD to a SUB, then store
    the passed DWORD in a local pointer variable.
    Just pass the address of the first element of the array, not the
    address of the array descripter:

    DIM MYARRAY?(1000)
    ARRAYADDRESS??? = VARPTR32(MYARRAY?(0))
    CALL MYSUB(A%, B%, ARRAYADDRESS???)

    Code:
    SUB MYSUB CDECL(X%, Y% [,ADDRESS???])
     DIM ARRAYPTR AS BYTE PTR   ;Make sure the PTR type matches the array type
     ARRAYPTR = ADDRESS???
     A? = @ARRAYPTR[N]   ;You can index into the array with the pointer
     .......
    END SUB
    For multidimensional arrays, just remember that the array data is
    stored in column major format in memory:

    Code:
    (0, 0)  (1, 0)  (2, 0)
    (0, 1)  (1, 1)  (2, 1)

    ------------------

    Comment


    • #3
      Thanks, Mr. Grant. I figured that would be the only way I could do it (or pass a flag which would then tell the sub to access either a shared array or a shared pointer).

      Too bad the CDECL attribute is wasted that way.

      ------------------
      Walt Decker

      Comment

      Working...
      X