Test pseudo-namespaces in C
In C you can create pseudo-namespaces by abusing structs of function pointers, making function calls look like `module.func(x)` instead of `func(x)`. A lot of people online spout that this creates overhead, but this should show that clang>=15.0.7 will still inline such function calls. GCC 11.3.1 is unable to inline the function, but will still call the function directly.
This commit is contained in:
29
Makefile
Normal file
29
Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
CC ?= clang
|
||||
|
||||
# compiler specific flags
|
||||
CFLAGS.gcc :=
|
||||
CFLAGS.clang :=
|
||||
|
||||
# general flags
|
||||
CFLAGS := \
|
||||
-Wall -Wextra -Werror -Wpedantic \
|
||||
-O3 -g -flto \
|
||||
-std=c2x \
|
||||
${CFLAGS.${CC}} \
|
||||
-DNAMESPACES \
|
||||
|
||||
LDFLAGS := \
|
||||
-flto \
|
||||
-Wl,-O3
|
||||
|
||||
dump.asm : test
|
||||
gdb $< -batch -ex 'disassemble main' > $@
|
||||
(gdb $< -batch -ex 'disassemble succ' >> $@) || true
|
||||
|
||||
test : main.o module.o
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
%.o : %.c
|
||||
$(CC) $(CFLAGS) -o $@ -c $^
|
||||
|
||||
Reference in New Issue
Block a user