Why and how C++ member functions in TrapC
Baltimore, MD (trapc.org) 26 January 2026 Why member functions? Because safety-critical systems deserve constructors and destructors. The member function implementation in TrapC happens entirely at compile-time, is as lightweight as C.
The member function is mangled by the compiler so the call foo.Bar() becomes Foo.Bar(&foo). Because C functions do not have a dot in them, when the compiler sees a function with a dot, it knows to translate it in this way, to look up the member function.
Convenient for object-oriented programming, and creates no overhead. TrapC does not carry a VFT virtual function table because it doesn’t have virtual functions nor derivation. TrapC doesn’t do C++ name-mangling because it doesn’t do function overloading.
struct Foo
{ void Bar() // really Foo.Bar()
{ puts("hello");
} };
int main()
{ struct Foo foo;
foo.Bar(); // really Foo.Bar(&foo)
return 0;
}
This week it was debugging member functions. Next is testing constructors and destructors. Pointers have hidden constructors and destructors in TrapC.
So this is essentially a crippled subset of C++. Which you call TrapC.
What is the point of this? In what way, and for whom, is this useful?
If you wanted C++ without inheritance, or function overloading, you can do that now, today, in Standard C++. Just don’t use inheritance, or function overloading. It’s basically C with struct member functions.
If you wanted to call C functions from a C struct via the dot or arrow operators, you can add function pointers to C structs today, in Standard C.
Xine – a video player from the early-to-mid 2000’s written in C – was using function pointers in C structs to do some pseudo / fake OO. Not a terribly original idea in 2026.
Or, you could do something marginally more useful: propose adding struct member functions to the C Standard, without overloading. Basically, syntax sugar for C function pointers.
There is something called std::shared_ptr in Standard C++. For all practical purposes, it behaves like a pointer. It also has constructors and destructors. I’d very much love to find out how exactly you are going to re-invent std::shared_ptr with hidden constructors and destructors and without any runtime overhead.
Final thoughts:
https://dictionary.cambridge.org/us/dictionary/english/bad-workman-blames-his-tools