Macro metaprogramming is awesome!..

Until it's not...

By Auri/h33p
github.com/h33p/talks

What is all this?

  • C preprocessor
  • Glorified copy paste tool

But why?

  • C89 did not have constants
  • Dennis Ritchie
  • ... wanted to C the world burn

What does it do?

Say we want to define and use a constant...

Step 1 - define it

Step 2 - use it

Step 3 - preprocess it

Step 4 - profit

Constant is just a named literal!

  • But where madness?

Level 1

Parametrized macros!

Step 1 - define it

Step 1 - define it

Step 2 - use it

Step 3 - preprocess it

Step 3 - preprocess it

Step 4 - compile

Step 5 - profit

Level 2

Cool strings

Step 1 - notice the hashtag

Step 2 - use as usual

Step 3 - preprocess it

Step 3 - preprocess it

Step 4 - compile

Step 5 - profit

Level 3

Generate functions

Basic networked variables

Basic networked variables

Basic networked variables

Basic networked variables

Basic networked variables

Same code as before

Step 1 - function for netvar

Step 2 - define netvars

Step 3 - use them!

Step 4 - preprocess...

Step 4 - preprocess

Step 4 - preprocess

Step 5 - run!

Step 5 - run!

Level 4

Config system

Step 1 - some config variable

Step 2 - future DLC...

Step 3 - use it!

Step 4 - use it more!!!

Step 5 - save config

Step 6 - load config

Step 7 - DOCONFIG?

Step 7 - DOCONFIG?

Step 7 - Oh no

Step 7 - SCONFIG

Step 7 - LCONFIG

Step 8 - Use it!

Step 8 - Use it!

Step 8 - Use it!

Step 8 - Use oh...

Step 9 - Debug it!

Step 9 - Debug it!

Step 9 - Debug it...

Step 9 - Yikes.

Step 10 - Cry!

So... Macros

  • Really awesome
  • Get tempted to fly to the moon
  • Get grilled, like Icarus!

Some links