best way to return (char *)

Steve Summit scs at envy.pika.mit.edu
Sun Jul 2 07:42:56 AEST 1989


In article <10345 at claris.com> kevin at 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 at adam.pika.mit.edu



More information about the Comp.lang.c mailing list