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:
olemorud
2023-06-06 11:32:12 +02:00
commit 0c33a58da0
7 changed files with 122 additions and 0 deletions

12
module.c Normal file
View File

@@ -0,0 +1,12 @@
#include "module.h"
inline int succ(int x)
{
return x+1;
}
struct exports module = {
.succ = succ,
};