Path: utzoo!attcan!uunet!husc6!bloom-beacon!envy.pika.mit.edu!scs From: scs@envy.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: best way to return (char *) Message-ID: <12365@bloom-beacon.MIT.EDU> Date: 1 Jul 89 21:42:56 GMT References: <1989Jun23.170749.23253@utzoo.uucp> <10345@claris.com> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 18 In article <10345@claris.com> kevin@claris.com (Kevin Watts) writes: >A similar approach, used by Apple in their upcoming GS/OS is as follows: >On input, pass a buffer with its length (including the space for the length) >in the first word (one could use a long instead). If the buffer is large >enough, the routine uses it, otherwise the routine returns an error code and >puts the size of the buffer it needs into the _second_ word of the buffer. Yuck. This sort of type punning within arrays always seems to me to be a holdover from assembly language days, before we had record structures. If you want an aggregate consisting of a buffer size, a required length, and a buffer, use a real structure; don't try to "assemble one out of spare parts." (I am aware that implementing variable-sized structures can be tricky, perhaps requiring an extra level of indirection, which is probably one reason punned array techniques remain popular.) Steve Summit scs@adam.pika.mit.edu