17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data Definitions<br />

Structures and Unions<br />

Struct structure type: creates a collection of one or more<br />

variables, possibly of different types, grouped together as a<br />

single unit.<br />

struct[*] [id] {<br />

type-qualifier [*] id [:bits]; } [id]<br />

One or more,<br />

semi-colon<br />

separated<br />

Zero<br />

or more<br />

For example:<br />

struct data_record {<br />

int a[2];<br />

int b : 2; /*2 bits */<br />

int<br />

c : 3; /*3 bits*/<br />

int d;<br />

} data_var; //data_record is a structure type<br />

//data_var is a variable<br />

Union type: holds objects of different types and sizes, with the<br />

compiler keeping track of size and alignment requirements. They<br />

provide a way to manipulate different kinds of data in a single<br />

area of storage.<br />

union[*] [id] { type-qualifier [*] id [:bits]; } [id]<br />

One or more,<br />

semi-colon<br />

separated<br />

Zero<br />

or more<br />

For example:<br />

union u_tab {<br />

int ival;<br />

long lval;<br />

float fval;<br />

}; //u_tag is a union type that can hold a float<br />

31

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!