Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!ficc!cliff From: cliff@ficc.uu.net (cliff click) Newsgroups: comp.lang.misc Subject: Re: Language Tenets Summary: q/r, returning structs Message-ID: <5096@ficc.uu.net> Date: 19 Jul 89 20:50:11 GMT References: <57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <1989Jul17.184707.415@maths.nott.ac.uk> Organization: Ferranti International Controls Lines: 43 In article <1989Jul17.184707.415@maths.nott.ac.uk>, anw@maths.nott.ac.uk (Dr A. N. Walker) writes: > [Good contributions from, inter alia, cik@l.cc.purdue.edu (Herman Rubin), > pds@quintus.UUCP (Peter Schachte), roelof@idca.tds.PHILIPS.nl (R. Vuurboom), > and suitti@haddock.ima.isc.com (Stephen Uitti) on the problem of "q r <- t/b".] > > (a) Is it a language deficiency if "q r <- t/b" cannot be sensibly > written? Answer: yes. Solutions on the lines of > > q = t/b; r = t%b; /* "and the optimiser should tidy up" */ > > are inadequate because I might want to write [deleted expressions with side effects...] Perhaps what we want is the ability to return a structure for any function call (even an infix or inlined one), and the ability to assign that structure to a mongrel structure we create on the fly. Given: struct{ float q, r; } divrem( float t, b ); and: float q[10], r[10], a[10], b[10]; we get: struct{ q[3], r[9] } = divrem( a[2], b[3] ); or: struct{ q[i++], r[j++] } = divrem( a[i], b[j] ); The lvalue is a structure of lvalues, each of the correct type for the structure but perhaps changing with each usage. This ability could be used to *pass* a structure we create on the fly, instead of filling in the fields in a temp structure: struct timething { int h, m, s }; void printime( struct timething foobar ); int hour, min, sec; [expressions using/setting hour, min, sec...] printime( struct timething { hour, min, sec } ); Flames, anybody? -- Cliff Click, Software Contractor at Large Business: uunet.uu.net!ficc!cliff, cliff@ficc.uu.net, +1 713 274 5368 (w). Disclaimer: lost in the vortices of nilspace... +1 713 568 3460 (h).