C language for MSX – lesson 3

da | Nov 30, 2023 | C language | 0 comments

C language for MSX

Column by Nicola Brogelli (Part 3)

Enumerations

The enum or enumerations are particular data types that contain a list of constants, each of which is associated with an integer value. Specifically, the constant values contained in the enumeration can be defined by the user or if there are no particular needs we can leave the association of the value to the constant to the language.

Below I report the syntax of an enumeration

enum enumeration_name {constant1, constant2, …};

The enum keyword is necessary to define the enumeration type “structure”, enumeration_name is the associated name, while the constants are shown inside the curly brackets. By default the integer values associated with the constants have a base of 0, therefore the first constant will have a value of 0, the second 1 etc.

enum week {Mon, Tue, Wed, Thu, Fri, Sat, Sun};

However, it is possible to associate custom values with constants and this is done using the following syntax:

enum seventh {Mon = 1, Tue = 2, Wed = 3, Thu = 4, Fri = 5, Sat = 6, Sun = 7};

Alternatively, it is possible to initialize only the first constant of the enumeration, thus doing all the other constants will have progressive values increased by one unit compared to the first constant.

enum seventh {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};

 

For those interested theMSX Italy Association created a R&D working group on C programming for MSX. For more info:associazioneMSXitalia@gmail.com

 

 

0 Comments

Submit a Comment

Your email address will not be published. I campi obbligatori sono contrassegnati *

Linguaggio C per MSX – lezione 6

C language for MSX – lesson 6

C language for MSX Column by Nicola Brogelli (Part 6) Arrays and Pointers Multidimensional Arrays Until now we have considered one-dimensional arrays, which required only one index to identify an element. C allows you to...

Linguaggio C per MSX – lezione 6

C language for MSX – lesson 5

C language for MSX Column by Nicola Brogelli (Part 5) Arrays and Array Pointers Arrays are sequences of variables of the same type that are stored consecutively in memory and which can be accessed using the same name...

MSXgl una libreria di giochi scritta in C

MSXgl a game library written in C

MSXgl is a game library written in C and intended for MSX computers. The goal of this library is to give C programmers the full feature set to create a high-performance game. Even though a C program can never be efficient...

Linguaggio C per MSX – lezione 2

C language for MSX – lesson 2

C language for MSX Column by Nicola Brogelli (Part 2) Type Conversions As we saw in the previous handout, in C every piece of data has a well-defined Type. When variables of different types appear in an expression, the compiler is often able...