Uses of \"short\" ?

berger at datacube.UUCP berger at datacube.UUCP
Wed Oct 16 09:10:00 AEST 1985


The main use would be when you create structures that describe the
layout of registers in hardware. In otherwords, when you are writing
a driver or something you might say:

struct deviceRegs {
	int8 csr0;
	int8 csr1;
	int16 dataport;
};

register struct deviceRegs *p = (struct deviceRegs *)0x40000;

	p->csr0 = 0xff;
		etc.

You want each structure element to be a particular size so you can access
particular 8 bit bytes or 16 bit words.  This does not protect you from
byte swapping and I suspect some compilers might throw in hidden alignments,
but in general it works and looks nice.

			Bob Berger 

Datacube Inc. 4 Dearborn Rd. Peabody, Ma 01960 	617-535-6644
	
ihnp4!datacube!berger
decvax!cca!mirror!datacube!berger
{mit-eddie,cyb0vax}!mirror!datacube!berger



More information about the Comp.lang.c mailing list