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.
23 lines
241 B
C
23 lines
241 B
C
|
|
#include <stdio.h>
|
|
|
|
#include "module.h"
|
|
|
|
int main()
|
|
{
|
|
int x = 4;
|
|
|
|
#ifdef NAMESPACES
|
|
#pragma message "namespaces enabled"
|
|
x = module.succ(x);
|
|
x = module.succ(x);
|
|
#else
|
|
x = succ(x);
|
|
x = succ(x);
|
|
#endif
|
|
|
|
printf("%d\n", x);
|
|
|
|
return 0;
|
|
}
|