Path: utzoo!attcan!uunet!mcsun!ukc!dcl-cs!gdt!gdr!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: <1989Dec18.112247.9730@gdt.bath.ac.uk> Date: 18 Dec 89 11:22:47 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <1989Dec2.210042.12668@twwells.com> <8129@cg-atla.UUCP> <1989Dec12.110042.29290@gdt.bath.ac.uk> <1989Dec14.182113.5398@twwells.com> Reply-To: exspes@gdr.bath.ac.uk (P E Smee) Organization: University of Bristol c/o University of Bath Lines: 48 In article <1989Dec14.182113.5398@twwells.com> bill@twwells.com (T. William Wells) writes: >In article <1989Dec12.110042.29290@gdt.bath.ac.uk> exspes@gdr.bath.ac.uk (P E Smee) writes: >The above is missing some casts. And it can be done as well with Well, I said I'd simplified it. Saving the pointers, zeroing the whole thing, and then putting the pointers back I considered, but the construct occurs in a frequently-used part of the program, so I was willing to sacrifice beauty for speed. I don't recall why I didn't substructure the stuff after the pointers, but I do recall thinking at the time that it would not be a great idea in context. I *have* localized the definition of my clear operation so that you only have to understand what I'm doing (and why) once in the program. >On the other hand, it has the advantage that it will likely >generate slightly better code than any of the other methods. the >first two methods, for example, are very likely to generate >several extra instructions to compute the amount of space to >clear. I was trusting the compiler to realize that the size of the structure was known at compile time (though not to me), and so to optimize that computation. My trust was repaid on the one machine where I looked at the object code generated. >Warning: null pointers and floating point zeros are *not* >necessarily represented by bit patterns of all zero bits. True, well known, and not an issue in my case. (In fact, on all my target machines, they are; but I've learned not to count on that.) I also contemplated (since the my struct was fixed size) putting the pointers at the end, and using one of them as the effective marker. However, that interacted badly with the paging algorithm on one of my target machines (extra paging to get at the most frequently used item) and didn't gain any compensating advantage on any of the others. I suppose I ought to say that the construct is *NOT* one that I am particularly proud of, and I don't find it beautiful, but it *IS* a taken-from-life example of where a zero-length entity could sensibly be used. (Which is all I meant it to be.) It is also well-commented in my original to indicate what I am doing, why I am doing it that way, and why I am not happy that I have done. -- Paul Smee, Univ of Bristol Comp Centre, Bristol BS8 1TW, Tel +44 272 303132 Smee@bristol.ac.uk :-) (..!uunet!ukc!gdr.bath.ac.uk!exspes if you MUST)