home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / c / 3345 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.6 KB  |  40 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Struct hack one last time (one last time)
  5. Message-ID: <1993Jan8.184304.10965@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Dec31.153931.7495@hubcap.clemson.edu> <1993Jan1.173852.26630@taumet.com> <1993Jan7.145117.8220@jarvis.csri.toronto.edu>
  8. Date: Fri, 8 Jan 1993 18:43:04 GMT
  9. Lines: 29
  10.  
  11. flaps@dgp.toronto.edu (Alan J Rosenthal) writes:
  12.  
  13. >steve@taumet.com (Steve Clamage) writes:
  14. >>An implementation is allowed to add padding to the end of a struct.
  15. >>Suppose that the implementation adds space to the end of each struct
  16. >>type where it encodes information used for run-time error checking.
  17.  
  18. >Can't do that... what happens when you malloc one of them?
  19.  
  20. >    struct whatever *p = (struct whatever *)malloc(sizeof(struct whatever));
  21.  
  22. >Immediately after the malloc, if p is not null you can start using the struct,
  23. >but it won't have that run-time-error-checking information, so it will fault.
  24.  
  25. The compiler is allowed to recognize calls to standard library functions.
  26. It could fix up the returned struct after the call to malloc (or realloc
  27. or calloc).  It would also have to interpret the size in case an array
  28. were being allocated:
  29.     extern size_t s;
  30.     struct w *p = malloc(s);
  31.     /* fixup s/sizeof(struct w) structs here */
  32.  
  33. You could subvert this via void* pointers, but that isn't the point.
  34. Presumably this is an optional checkout mode, and such modes typically
  35. impose constraints on programmers.  If you play games to subvert type
  36. checking, you are going to have problems.
  37. -- 
  38.  
  39. Steve Clamage, TauMetric Corp, steve@taumet.com
  40.