C Game Dev Enum



  1. C++ Enum
  2. C++ Enum Naming
< c‎ | language
C
Language
Headers
Type support
Program utilities
Variadic function support
Error handling
Dynamic memory management
Date and time utilities
Strings library
Algorithms
Numerics
Input/output support
Localization support
Atomic operations(C11)
Thread support(C11)
Technical Specifications

The main idea is that I declare all enums in the game in 1 file, and then import that file when I need to use a certain enum from it, rather than declaring it in the file where I need to use it. I do this because it makes things clean, I can access every enum in 1 place rather than having pages openned solely for accessing one enum. Enumeration is a user defined datatype in C/C language. It is used to assign names to the integral constants which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration. The following is the syntax of enums. Unless you know how long the game loop will be on every computer, making your sleep a constant is generally bad practice. If you know that you want 2fps, a good way to keep it in line is get the time at the start of the game loop, then at the end, find out the difference, and use that to calculate the amount of time needed to sleep to keep the step the same. E.g, If the loop takes 0.1s,. Rizz (ریز) is a tiny, multi-platform, and minimal game/app development framework, Written in C language. Inspired by The Machinery and sokol libs.It's currently a work in progress, features and improvements will be added constantly to different platforms.

C language
Basic concepts
Keywords
Preprocessor
Statements
Expressions
Initialization
Declarations
Functions
Miscellaneous
History of C
Technical Specifications
Declarations
pointer
array
bit field
atomic types(C11)
(C99)
(C11)
storage duration and linkage
external and tentative definitions
(C11)
attributes(C23)

An enumerated type is a distinct type whose value is a value of its underlying type (see below), which includes the values of explicitly named constants (enumeration constants).

[edit]Syntax

Enumerated type is declared using the following enumeration specifier as the type-specifier in the declaration grammar:

enumattr-spec-seq(optional)identifier(optional){enumerator-list}

where enumerator-list is a comma-separated list (with trailing comma permitted)(since C99) of enumerator, each of which has the form:

enumeration-constantattr-spec-seq(optional) (1)
enumeration-constantattr-spec-seq(optional)=constant-expression (2)

where

identifier, enumeration-constant - identifiers that are introduced by this declaration
constant-expression -integer constant expression whose value is representable as a value of type int
attr-spec-seq -(C23)optional list of attributes,
  • applied to the whole enumeration if appears after enum,
  • applied to the enumerator if appears after enumeration-constant

As with struct or union, a declaration that introduced an enumerated type and one or more enumeration constants may also declare one or more objects of that type or type derived from it.

[edit]Explanation

Each enumeration-constant that appears in the body of an enumeration specifier becomes an integer constant with type int in the enclosing scope and can be used whenever integer constants are required (e.g. as a case label or as a non-VLA array size).

C++ Enum

If enumeration-constant is followed by = constant-expression, its value is the value of that constant expression. If enumeration-constant is not followed by = constant-expression, its value is the value one greater than the value of the previous enumerator in the same enumeration. The value of the first enumerator (if it does not use = constant-expression) is zero.

The identifier itself, if used, becomes the name of the enumerated type in the tags name space and requires the use of the keyword enum (unless typedef'd into the ordinary name space).

Each enumerated type is compatible with one of: char, a signed integer type, or an unsigned integer type. It is implementation-defined which type is compatible with any given enumerated type, but whatever it is, it must be capable of representing all enumerator values of that enumeration.

Enumerated types are integer types, and as such can be used anywhere other integer types can, including in implicit conversions and arithmetic operators.

[edit]Notes

Unlike struct or union, there are no forward-declared enums in C:

Enumerations permit the declaration of named constants in a more convenient and structuredfashion than does #define; they are visible in the debugger, obey scope rules, and participate in the type system.

or

Moreover, as a struct or union does not establish its scope in C, an enumeration type and its enumeration constants may be introduced in the member specification of the former, and their scope is the same as of the former, afterwards.

[edit]Example

Output:

[edit]References

  • C17 standard (ISO/IEC 9899:2018):
  • 6.2.5/16 Types (p: 32)
  • 6.7.2.2 Enumeration specifiers (p: 84-85)
  • C11 standard (ISO/IEC 9899:2011):
  • 6.2.5/16 Types (p: 41)
  • 6.7.2.2 Enumeration specifiers (p: 117-118)
  • C99 standard (ISO/IEC 9899:1999):
  • 6.2.5/16 Types (p: 35)
  • 6.7.2.2 Enumeration specifiers (p: 105-106)
  • C89/C90 standard (ISO/IEC 9899:1990):
C Game Dev Enum
  • 3.1.2.5 Types
C Game Dev Enum
  • 3.5.2.2 Enumeration specifiers
C game dev enumerated

[edit]Keywords

[edit]See also

C++ Enum Naming

Retrieved from 'https://en.cppreference.com/mwiki/index.php?title=c/language/enum&oldid=125327'