Multiple character "character constants"

Ken Turkowski ken at turtleva.UUCP
Mon Oct 10 15:54:02 AEST 1983


I realize that I may be opening up a can of worms with this question,
but I am trying to put together a package that will verify headers for
files in a machine-independent way.

Everyone knows that different machines have their own way of packing
bytes into words and longwords.
On the big-endian side are IBM and the 68000 with their (excuse me, K&R)
	struct long { char byte0, byte1, byte2, byte3; };
The little-endian VAX and the 16032 with
	struct long { char byte3, byte2, byte1, byte0; };
and the mongrel PDP-11 with
	struct long { char byte1, byte0, byte3, byte2; };
so that only the ordering of bytes in character arrays remains constant
among different machines, not the ordering of bytes in shorts or longs.

Machine independence therefore requires that programs treat the byte
as the holiest quantum of information,
and that all other data structures are derived from the ordering of bytes.

Now, suppose that file headers are four bytes, and that it is desired
to do a switch on this quantity.  C does allow the use of multiple
character "character constants", supposedly accommodating as many
characters as can fit into an int.  On a 32-bit machine,
this means that 4 byte character constants can be constructed.
For example,
	switch (headercode) {
	    case 'eqn ':
	    case 'nrff':
	    case 'fort':
	    case 'pasc':
	}
Now, the question is this:  how are the characters packed into the
int?  In the same way that strings would be packed into a 4-character
array starting at the same address?  This does seem most reasonable,
although I can't seem to find anything definitive on the subject.
Also, do all C compilers support the multiple character "character
constants"?

			Ken Turkowski
		    CADLINC, Palo Alto
		{decwrl,amd70}!turtlevax!ken



More information about the Comp.lang.c mailing list