home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18485 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  1.6 KB

  1. Xref: sparky comp.lang.c:18485 comp.std.c:3218
  2. Path: sparky!uunet!tdat!tools3!swf
  3. From: swf@tools3teradata.com (Stan Friesen)
  4. Newsgroups: comp.lang.c,comp.std.c
  5. Subject: Re:  Is this ANSI: final (long)
  6. Message-ID: <1623@tdat.teradata.COM>
  7. Date: 16 Dec 92 19:19:33 GMT
  8. References: <Zc15uB4w165w@quest.UUCP> <723773123.1323@hitech.com.au> <alien.01ss@acheron.amigans.gen.nz> <Bz3n1I.73o@unx.sas.com> <1363@mwtech.UUCP>
  9. Sender: news@tdat.teradata.COM
  10. Distribution: world
  11. Organization: NCR Teradata Database Business Unit
  12. Lines: 30
  13.  
  14. In article <1363@mwtech.UUCP>, martin@mwtech.UUCP (Martin Weitzel) writes:
  15. |> In article <Bz3n1I.73o@unx.sas.com> sasghm@theseus.unx.sas.com (Gary Merrill) writes:
  16. |> :In article <alien.01ss@acheron.amigans.gen.nz>, alien@acheron.amigans.gen.nz (Ross Smith) writes:
  17. |> :|> 
  18. |> :|> ... Why not just
  19. |> :|> use a pointer instead of kludging it up with a fake array?
  20. |> :|> [example deleted]
  21. |> :
  22. |> :The point is this:  If you are dynamically allocating *both* the
  23. |> :structure and the data, the approach you suggest requires *two*
  24. |> :separate allocations (and two separate frees if you will be freeing
  25. |> :the stuff). ...
  26. |>
  27. |> Yes, and there's another point:  With a single allocation you may
  28. |> memcpy/memmove/memcmp/[f]read/[f]write the whole easily. ...
  29.  
  30. Of course you could solve both problems by using the solution we came up with here:
  31.  
  32.     struct data {
  33.         char    *dptr
  34.         ...
  35.     };
  36.  
  37.     struct data *dp = malloc(sizeof(struct data) + strlen(string));
  38.     dp->dptr = (char *)dp + sizeof(struct data);
  39.  
  40. -- 
  41. sarima@teradata.com            (formerly tdatirv!sarima)
  42.   or
  43. Stanley.Friesen@ElSegundoCA.ncr.com
  44.