home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11756 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.6 KB  |  61 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!sun-barr!ames!agate!linus!aquila.sni-usa.com!news.sni.de!uranium!josef
  3. From: Josef Moellers <mollers.pad@sni.de>
  4. Subject: Re: Variable length records
  5. Sender: josef@nixpbe.sni.de (Moellers)
  6. Message-ID: <josef.712481263@uranium>
  7. Date: Thu, 30 Jul 1992 07:27:43 GMT
  8. References: <24137@castle.ed.ac.uk> <rbjmzg-.gurgle@netcom.com>
  9. Organization: Siemens Nixdorf Info.Sys. AG, Paderborn, Germany
  10. Lines: 49
  11.  
  12. In <rbjmzg-.gurgle@netcom.com> gurgle@netcom.com (Pete Gontier) writes:
  13.  
  14. >adam@castle.ed.ac.uk (Adam Hamilton) writes:
  15.  
  16. >>    During my last spell at teaching C, I was asked what support C
  17. >>could give for variable length records.  (Not variant records which I can
  18. >>do with a union).  I was unable to answer the question, so promised to
  19. >>seek help (this means you).
  20.  
  21. >Funny you ask; I just did some cursory research on this very topic. I had
  22. >written some Mac code using declarations thus:
  23.  
  24. >typedef struct
  25. >{
  26. >    short   count;
  27. >   float   data[ ];
  28. >}
  29. >foo;
  30.  
  31. >I refer to the second member as an "open array." Its behavior is this:
  32. >    o  it may appear only as the last member of a structure
  33. >    o  it does not contribute to the value returned by sizeof(foo)
  34. >   o  it may be addressed, of course, with an arbitrary index
  35.  
  36. >I got worried about its portability so I paged through some manuals.
  37. >Both major C compilers for the Mac support it. Turbo C and Microsoft
  38. >C for the PC support it. According to Harbison and Steele, ANSI does
  39. >*not* support it. And from experience I know that AT&T cfront 2.1 (the
  40. >most common "standard" for C++) does not support it. I'm a little bit
  41. >suprised that it's not in the ANSI standard, but after my research I
  42. >felt it was common enough that I'd use it with impunity. And now I've
  43. >just checked with 'gcc' 1.39, and it doesn't like it. Perhaps 2.x does.
  44.  
  45. You COULD just declare it as "data[1]", which will keep EVERY compiler
  46. happy! Only now the burden is upon YOU to take this one float into
  47. consideration when allocating/reading the data structure.
  48.  
  49. >>P.S.  I already know that Unix will have a problem with variable length
  50. >>records since it doesn't know about records.  Nevertheless, if anyone knows
  51. >>of an attempt to solve this I will be grateful to hear about it.
  52.  
  53. >Not knowing about records simply means you have to implement it yourself.
  54. >There are no problems, as long as your compiler cooperates, with UNIX.
  55. >-- 
  56. > Pete Gontier // EC Technology // gurgle@netcom.com
  57. -- 
  58. | Josef Moellers        | c/o Siemens Nixdorf Informationssysteme AG  |
  59. |  USA: mollers.pad@sni-usa.com    | Abt. STO-XS 113       | Riemekestrasse   |
  60. | !USA: mollers.pad@sni.de    | Phone: (+49) 5251 835124 | D-4790 Paderborn |
  61.