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:
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(Namespaces)
|
||||
|
||||
add_executable(main
|
||||
module.c
|
||||
main.c)
|
||||
|
||||
target_compile_options(main
|
||||
PRIVATE
|
||||
-Werror -Wall -Wextra -O3 -g -std=c2x -flto)
|
||||
|
||||
target_link_options(main
|
||||
PRIVATE
|
||||
-flto -Wl,-O2)
|
||||
|
||||
target_compile_definitions(main
|
||||
PRIVATE
|
||||
-DNAMESPACES)
|
||||
Reference in New Issue
Block a user