sizeof(struct) and padding

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Mon Oct 22 11:34:46 AEST 1990


In article <98 at screamer.csee.usf.edu>, stelmack at 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:
	<directory>
	<text version>
	<binary version>
where the <directory> is
	<binary edition> <pointer to binary version>
and <binary edition> is some magic tag that lets you determine whether
the binary version is appropriate for this machine&os&compiler&release.
If it is, the <pointer to binary version> 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.



More information about the Comp.lang.c mailing list