(loose ends)

CIS241

System-Level Programming and Utilities

C - The Rest

Erik Fredericks, frederer@gvsu.edu
Fall 2025

Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers

CIS241 | Fredericks | F25 | 45-c-the-rest

Enumerations (enums)

Enums let you name "options"

  • Can increase readability
  • … but doesn’t actually add any new functionality

All values are just an integer underneath

  • Typically start at 0 and count up
  • But we can override that if we want!
enum rank {
    CAPTAIN,
    FIRST_MATE,
    QUARTERMASTER
};
enum rank my_rank = QUARTERMASTER;
.

typedef (again)

What does typedef do?

  • Gives an existing type a new name!
  • We can use that here to trim down 'enum rank'
typedef enum rank {
   CAPTAIN = 5,
   FIRST_MATE = 4,
   QUARTERMASTER = 3
} rank;
rank your_rank = CAPTAIN;
CIS241 | Fredericks | F25 | 45-c-the-rest

Unions

What does a struct do?

  • Store multiple pieces of data together as a bundle

A union does the opposite: Stores multiple types of data in the same place

  • All types use the same memory
  • Can only store one at a time
  • You are responsible for interpreting it!
CIS241 | Fredericks | F25 | 45-c-the-rest

Unions

union Data {
    int i;
    double d;
    char c;
};
union Data var;
var.d = 3.14;
CIS241 | Fredericks | F25 | 45-c-the-rest

Other keywords

A variable preceded by const cannot be changed

A variable preceded by static maintains its value outside of the normal scope

  • E.g., a static int in a function will have the same value across function calls
CIS241 | Fredericks | F25 | 45-c-the-rest

Other libraries

Working with standard libraries is easy

  • No extra work
  • E.g., stdio.h

You can also use custom libraries

  • May need to pass additional flags to gcc
  • Linker flags: -l or -L options
  • Includes: -I options
CIS241 | Fredericks | F25 | 45-c-the-rest
(thats all)

And so

 
 
 
 
 
 
 

CIS241 | Fredericks | F25 | 45-c-the-rest

meaning, one memory region and only one variable can be active useful for semantics or memory efficiency

update one of the others and print both - garbage shown in the other

pointer might mean that the pointer or the value is const void update() { static int x = 0; x++ printf("%d\n", x) } int main(update(); update(); update();)

show rl (ncurses), raylib, sdl