Uses of \\"short\\" ?

Niket K. Patwardhan bilbo.niket at LOCUS.UCLA.EDU
Tue Oct 22 04:50:44 AEST 1985


It is particularly important when you are sharing data between machines with
different integer models (ie. little endian vs. big endian). You then want
"int16" to mean something very specific (16 bits in little endian format).
I chose little endian because thats what most networks seem to use (as
opposed to IBM or Motorola CPUs). Without being able to specify exactly
how many bits you want to use, porting programs between machines with
different ideas of what an int, long, short or char is can be real painful.
NOTE even "char" is not sacred, KL10s can define them as any number of bits
upto 36(!!) with 6, 8 and 9 being values that support various types of TOPS-10
(their OS) characters.

What I would really like to see is that the bit-field semantics be changed a
little.

struct x
{
	unsigned a:18;
	unsigned b:18;
	unsigned c:36;
}

should be packed together as close as possible, taking up 9 bytes (octets),
rather than the 4+4+5 it takes up on a 16-bit word machine, or the 4+4+8
bytes it takes up on a 32-bit machine. If you wanted it to be the way it is
today you would define it as

struct x
{
	struct { unsigned a:18; };
	struct { unsigned b:18; };
	struct { unsigned c:32; };
}



In addition, there would be no harm done if 

unsigned a:13;

were allowed as a declaration.



BTW, can somebody give me the correct address to reach everybody in
net.lang.c and std.c. I suspect the ones I am using reach only a small subset
of the people in these groups.



More information about the Comp.lang.c mailing list