Path: utzoo!attcan!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: sizeof(struct) and padding Message-ID: <4033@goanna.cs.rmit.oz.au> Date: 22 Oct 90 01:34:46 GMT References: <1229@sun13.scri.fsu.edu> <1990Oct20.003222.25439@athena.mit.edu> <98@screamer.csee.usf.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 54 In article <98@screamer.csee.usf.edu>, stelmack@screamer.csee.usf.edu (Gregory M. Stelmack) writes: > Many of us use binary files because our OS does not differentiate > between text and binary files. I'm sorry, but this is just so totally wierd. I can understand the reasoning that goes "this operating system forces me to distinguish between binary and text, and this is one of the cases where it wants binary, so I'm stuck with binary". But I don't see why an operating system that doesn't force you to use a binary representation is a reason for doing so anyway. > My Suns at school do not even have the ability to choose which one to > open -- look at my recent question about reading/writing binary files... Oh come on. The Suns at your school *do* give you the choice of opening a file for binary transput or opening it for text transput. Either way, you write exactly the same code. This is like complaining that your local milk company doesn't let you choose whether to drink from the bottle or out of a glass because it gives you exactly the same bottle in both cases. The realistic way to put it is that UNIX-based systems like the Suns let you have *any* mix of text and binary within the same file. You can, for example, put source code (text), object code (binary), and archives (structured) into archives (.a files, managed by the 'ar' command). This is a facility that operating systems which distinguish between text and data *deny* you. Stop and think about it. The ability to mix text and binary in one file gives us the best of both worlds. Suppose we structure a file like this: where the is and is some magic tag that lets you determine whether the binary version is appropriate for this machine&os&compiler&release. If it is, the is a decimal integer or integers encoding the address of the binary version, you just go there and slurp it up. If the binary version isn't appropriate, you read the text version, rewrite the binary version, and update the header. That way you get the speed benefit of reading a binary version, and the portability benefit of having a text version, and you've still got only one file to worry about. What makes this possible? *NOT* distinguishing between text and binary in the os. > So, I'd just as soon stick with my binary files...might as well with binary > data. You'd better stick with your machine too... -- Fear most of all to be in error. -- Kierkegaard, quoting Socrates.