home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sunic!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Newsgroups: comp.lang.c
- Subject: Re: Variable length records
- Message-ID: <1992Jul29.160618.27224@klaava.Helsinki.FI>
- Date: 29 Jul 92 16:06:18 GMT
- References: <24137@castle.ed.ac.uk> <rbjmzg-.gurgle@netcom.com> <1992Jul25.091702.15993@klaava.Helsinki.FI>
- Organization: University of Helsinki
- Lines: 22
-
- In an earlier article I asked for what the advantages of using the
- non-standard "struct { ...; float data[];}" or the tricky but more
- standard "struct {...; float data[1];}" for structures where the data
- array may be of varying lengths. I offered the "struct {...; float *}"
- version instead, as it is strictly conforming and will work everywhere.
-
- The reasons for the trickery versions were convenience (no need for
- managing a separately allocated array), less wasted space (no additional
- pointer), and no need for a pointer dereference. Your mileage may vary,
- but I don't think these are very good reasons, at least under normal
- circumstances. If speed or size is critical, one's values may be
- different.
-
- One point which I didn't think of until now (and which doesn't seem to
- have been pointed out by others) is that the '[]' and '[1]' versions
- don't allow using the structures as values, like for assignment,
- parameter passing and returning as function values. This may or may not
- be important, but it is something you have to check for, as it could
- lead to difficult bugs, as such usage doesn't look wrong in itself.
-
- --
- Lars.Wirzenius@helsinki.fi
-