futzing around with macros some more
This commit is contained in:
parent
376ef0353f
commit
79436cc731
4
Makefile
4
Makefile
@ -1,7 +1,9 @@
|
|||||||
CD = cd
|
CD = cd
|
||||||
RM = rm -v
|
RM = rm -v
|
||||||
|
|
||||||
export CD RM
|
CFLAGS := -std=c99
|
||||||
|
|
||||||
|
export CD RM CFLAGS
|
||||||
|
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
42
gowrikumar/src/04b-macrodef.c
Normal file
42
gowrikumar/src/04b-macrodef.c
Normal 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
|
||||||
|
*/
|
@ -4,7 +4,7 @@ ALL_BIN := $(patsubst %.c,$(BINDIR)/%,$(wildcard *.c))
|
|||||||
|
|
||||||
|
|
||||||
$(BINDIR)/%: %.c
|
$(BINDIR)/%: %.c
|
||||||
$(CC) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
all: $(ALL_BIN)
|
all: $(ALL_BIN)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user