C
The shaman's Rockbiter: the bedrock weapon. Operating systems, embedded devices, and the runtimes of other languages are written in it, a hand's width from the metal.
Wears the Classic spell Rockbiter Weapon.
Coming from Python: The syntax looks familiar and nothing else is. There is no garbage collector: you allocate memory, you free it, and strings are arrays of characters that end in a zero because somebody has to end them.
Summoning the language
First summoning
Save the incantation as hello.c, compile it with gcc or clang, run the binary. That compile step IS the lesson: C becomes a machine program before it runs.
#include <stdio.h>
int main(void) {
for (int i = 1; i <= 3; i++) printf("cast %d\n", i);
return 0;
}
// $ gcc hello.c -o hello && ./helloThe temper
Pointers are addresses, and arrays decay to them; a string is a pointer to the first character. Draw memory on paper: four boxes, one arrow. Every segfault you ever meet is an arrow pointing at the wrong box.
char name[] = "Chromie";
char *p = name; /* p points at the C */
printf("%c\n", *p); /* C */
printf("%c\n", *(p+2)); /* r */First real chore
Write a tiny program a day for two weeks: a calculator, a file copier, a word counter. Use structs to bundle data, malloc and free pairs for dynamic memory, and run everything under the address sanitizer so the bugs announce themselves instead of lurking.
typedef struct { char name[32]; int rank; } Spell;
Spell s = {"fireball", 3};
printf("%s rank %d\n", s.name, s.rank);
// $ gcc -fsanitize=address day7.c -o day7