Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!voder!pyramid!prls!philabs!linus!alliant!merk!xylogics!transfer!crackers!m2c!umvlsi!dime!smectos!eli From: eli@smectos.gang.umass.edu (Eli Brandt) Newsgroups: comp.lang.pascal Subject: returning records Message-ID: <17556@dime.cs.umass.edu> Date: 27 Jul 90 15:31:17 GMT References: <950036@hpclapd.HP.COM> <1990Jul25.173213.24892@uwasa.fi> <15365@thorin.cs.unc.edu> Sender: news@dime.cs.umass.edu Reply-To: eli@smectos.CS.UMASS.EDU (Eli Brandt) Organization: University of Massachusetts, Amherst Lines: 38 In article <15365@thorin.cs.unc.edu> hardarso@arras.cs.unc.edu (Kari Hardarson) writes: >I have two questions about TP. Is there a good reason why a function >in TP cannot return a record? Also: is there any way to implement (deleted; I can't answer that one) Well, you don't want to pass records on the stack, but there should be a way to return pointers to them with having to explicitly reference and dereference them. One way around this is to return a string of the proper size and then typecast it: type complex = record a, b: real end; cstr = string[11]; { you get element 0, too } function cAdd(x, y: complex): cstr; var sum: complex; begin with sum do begin a := x.a+y.a; b := x.b+y.b; end; cAdd := cstr(sum); end; const c1: complex = (a:1; b:1); { sorry, don't remember the format } c2: complex = (a:-3; b:2); var c3: complex; begin c3 := complex(cAdd(c1, c2)); end. Consider this more pseudocode than actual TP code. I'm just entering this from memory, but I have used this trick. I ran it through cpp first to convert cAdd to complex(cAdd) to simplify the syntax.