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