Skip to content
Snippets Groups Projects
Commit 148120fe authored by Jake Feddersen's avatar Jake Feddersen
Browse files

Notes

parent d7df0c0e
No related branches found
No related tags found
No related merge requests found
//#include <stdio.h>
#define NPC_SMART 0x00000001
#define NPC_TELE 0x00000002
#define NPC_TUNNEL 0x00000004
#define NPC_ERRATIC 0x00000008
#define MAX_ROOMS 20
#define NOTHING
#define to_string(s) #s
#define table_element(e) { e, #e }
struct {int, char * } table[] = {
table_element(i);
table_element(j);
};
#define has_characteristic(character, bit) \
((character) & NPC_##bit)
#ifdef NOTHING
int Idontmatter = MAX_ROOMS;
#endif
// Not the best, evalues each argument twice
#define min(x, y) (x < y ? x : y)
int characteristics = rand() % 16;
// Better, evaluates each argument once and uses those results
#define max(x, y) ({ \
typeof (x) _x = x; \
typeof (y) _y = y; \
_x > _y ? _x : _y; \
})
int main(int argc, char *argv[]) {
MAX_ROOMS;
min(3, 4);
#if 0
min(foo(x), bar(x));
max(foo(x), bar(x));
if (10 > min(foo(x), bar(x))) {
}
#endif
int x = NOTHING;
if(has_characteristic(characteristic, SMART)) {
// This is a smart monster
} else {
// This is a not smart monster
}
to_string(Foo);
return 0;
}
File added
#include <stdio.h>
// Type func: pointer to function that returns void and takes void
typedef void (*func)(void);
void zero()
{
printf(__FUNCTION__);
}
void one()
{
printf(__FUNCTION__);
}
void two()
{
printf(__FUNCTION__);
}
void three()
{
printf(__FUNCTION__);
}
void four()
{
printf(__FUNCTION__);
}
int main(int argc, char *argv[]) {
func table[] = {
zero,
one,
two,
three,
four
};
int i;
for( i = 0; i < 5; i++) {
table[i]();
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment