17.05.2015 Views

TMS34010 C Compiler - Al Kossow's Bitsavers

TMS34010 C Compiler - Al Kossow's Bitsavers

TMS34010 C Compiler - Al Kossow's Bitsavers

SHOW MORE
SHOW LESS

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

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

<strong>TMS34010</strong> C Language - Declarations<br />

• K&R states that structure and union member names must be mutually<br />

distinct. In TMS3401 0 C, members of different structures or unions<br />

can have the same name. However, this requires that references<br />

to the member be fully qualified through all levels of nesting.<br />

o<br />

<strong>TMS34010</strong> C allows assignment to and from structures, passing structures<br />

as parameters, and returning structures from functions.<br />

• K&R contains a statement about the compiler determining the type of a<br />

structure reference by the member name. Since TMS3401 0 C does not<br />

require member names to be unique, this statement does not apply. <strong>Al</strong>l<br />

structure references must be fully qualified as members of the structure<br />

or union in which they were declared.<br />

Added Type - Enumeration Declarations<br />

Enumerations allow the use of named integer constants in TMS3401 0 C. The<br />

syntax of an enumeration declaration is similar to that of a structure or union.<br />

The keyword enum is substituted for struct or union, and a list of enumerators<br />

is substituted for the list of members.<br />

Enumeration declarations have a tag, as do structure and union declarations.<br />

This tag may be used in future declarations, without repeating the entire declaration.<br />

The list of enumerators is simply a comma-separated list of identifiers. Each<br />

identifier can be followed by an equal sign and an integer constant. If there<br />

is no enumerator followed by an = sign and a value, then the first enumerator<br />

is assigned the value 0, the next is 1, the next is 2, etc. An identifier with an<br />

assigned value assumes that value; the next enumerator is assigned that value<br />

+ 1, the next is the preceding value + 1, etc. The assigned value may be negative,<br />

but the increments are still by positive 1.<br />

The size of an object of type enum is determined as follows: if any of the object's<br />

enumerators have negative values, the object occupies 32 bits. Otherwise,<br />

the object occupies the minimum number of bits required to represent<br />

the largest enumerator value and is considered to be unsigned.<br />

Unlike structure and union members, enumerators share their name space with<br />

ordinary variables and, therefore, must not conflict with variables or other enumerators<br />

in the same scope.<br />

Enumerators can appear wherever integer constants are required; thus, they<br />

can be used in arithmetic expressions, case expressions, etc.· In addition, explicit<br />

integer expressions may be assigned to variables of type enum. The<br />

compiler does no range checking to insure the value will fit in the enumeration<br />

field. The compiler does, however, issue a warning message if an enumerator<br />

of one type is assigned to a variable of another.<br />

Here's an example of an enumerator declaration:<br />

enum color<br />

red,<br />

blue,<br />

green 10,<br />

orange,<br />

purple -2,<br />

cyan } :X;<br />

4-9

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

Saved successfully!

Ooh no, something went wrong!