31.07.2013 Views

RAPL 3 - Reference Guide. - Phoenix Goucher

RAPL 3 - Reference Guide. - Phoenix Goucher

RAPL 3 - Reference Guide. - Phoenix Goucher

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.

28 Data Types and Variables<br />

Enumerated Types<br />

It is often convenient to refer to the values of a variable by name, rather than by<br />

number. For example, when referring to the colour of a test-tube, we can define:<br />

enum<br />

red,<br />

orange,<br />

yellow,<br />

green,<br />

blue<br />

end enum colour_type<br />

This defines type colour_type as type int, and creates the special constants red,<br />

orange, yellow, green and blue, which will have values 0, 1, 2, 3, and 4,<br />

respectively. These constants can be used anywhere a numerical constant would<br />

be appropriate.<br />

This allows a particular value to be associated with an identifier in the list.<br />

Syntax<br />

enum<br />

item_list<br />

end enum enum_identifier<br />

where<br />

enum and end enum are required,<br />

enum_identifier is the name of the enum,<br />

and<br />

item_list is a comma-separated list of items, where each item can be a simple<br />

identifier<br />

identifier<br />

or a statement<br />

identifier = constant_expression<br />

Examples<br />

Example Description<br />

enum<br />

num_a,<br />

num_b,<br />

num_c<br />

end enum x<br />

enum<br />

bit_0 = 1,<br />

bit_1 = 2,<br />

bit_3 = 4<br />

end enum y<br />

enum<br />

x,<br />

y,<br />

z<br />

end enum letters<br />

x is an int<br />

num_a is the constant 0<br />

num_b is the constant 1<br />

num_c is the constant 2<br />

y is an int<br />

bit_0 is the constant 1<br />

bit_1 is the constant 2<br />

bit_3 is the constant 4<br />

This is illegal after the previous two declarations. The<br />

constant identifiers must be unique within the same<br />

scope.

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

Saved successfully!

Ooh no, something went wrong!