[comp.lang.pascal] Returning record-type from a function in TP

MATHRICH@umcvmb.missouri.edu (Rich Winkel UMC Math Department) (02/07/89)

>>... (text deleted)...
>>Borland has make lots of useful extensions to the
>>language, but they have overlooked what I believe are the two most
>>obvious extensions:
>>
>>    1) allowing functions to return user defined types
>
>If you're talking about returning record types, which is non-standard,
>they'll have to change how the return value is passed back.  At present,
>Borland's TP uses AX register to pass back value.  You'd need to use
>either the stack segment or some other segment to return the value.

Not true.  Pointers and longints are returned in dx:ax, reals are returned in
dx:bx:ax, and strings are returned via a doubleword pointer to a dynamic
variable, both of which the caller allocates on the stack.  The last method
would work fine for returning arbitrary datatypes, if only the compiler was
smart enough to deal with it.  (using CASE in the type declaration to treat the
same memory as STRING and RECORD didn't work in 4.0.  I haven't tried it in 5.0)
The next best thing would be to define
TYPE PTREC=^MYREC;
     MYREC=RECORD xx;xx;xx ... END;
FUNCTION MYFUNC(xxxx):PTREC;

Rich Winkel