futzing around with macros some more

This commit is contained in:
Dan Buch 2011-06-18 14:28:00 -04:00
parent 376ef0353f
commit 79436cc731
3 changed files with 46 additions and 2 deletions

View File

@ -1,7 +1,9 @@
CD = cd
RM = rm -v
export CD RM
CFLAGS := -std=c99
export CD RM CFLAGS
all:

View File

@ -0,0 +1,42 @@
/**
* :author: Dan Buch (daniel.buch@gmail.com)
*/
#include <stdio.h>
#define f(a, b) a##b
#define g(a) #a
#define h(a) g(a)
#define border(c) \
for (int i = 0; i < 60; i++) { \
printf(c); \
} \
printf("\n");
int main()
{
printf("%s\n", h(f(1, 2)));
printf("%s\n", g(f(1, 2)));
printf("%s\n", g(printf("dogs rule cats drool\n")));
char * hambones = "Cats! " g(ham);
char * bonesham = "Meats! " g(bones);
char * tmp;
border("-");
printf("bonesham = %s\n", bonesham);
printf("hambones = %s\n", hambones);
border("-");
tmp = f(ham, bones);
f(ham, bones) = f(bones, ham);
f(bones, ham) = tmp;
printf("bonesham = %s\n", bonesham);
printf("hambones = %s\n", hambones);
return 0;
}
/* vim:filetype=c:fileencoding=utf-8
*/

View File

@ -4,7 +4,7 @@ ALL_BIN := $(patsubst %.c,$(BINDIR)/%,$(wildcard *.c))
$(BINDIR)/%: %.c
$(CC) -o $@ $<
$(CC) $(CFLAGS) -o $@ $<
all: $(ALL_BIN)