C++ Style Member Functions in TrapC

Why and how C++ member functions in TrapC

TrapC Member FunctionBaltimore, 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.

Leave a Reply

Your email address will not be published. Required fields are marked *