TrapC DotThis, DotDot, ThisArrow and Scoper Operators

A bit of syntactic candy in TrapC with C++ ‘this’

Dot-ThisBaltimore, MD (trapc.org) 2 February 2026 -TtrapC extends the C programming language with support for the TrapC dot-this operator and includes for C++ code compatibility this-> and :: support.

Having ‘this’ in TrapC is different from C++ in a subtle way. The TrapC ‘this’ pointer is a hidden function parameter called ‘this’. A member function call of foo.Bar() is interpreted as Foo.Bar(&foo) by the TrapC expression parser, with &foo passed as hidden variable named ‘this’. TrapC uses a lightweight C-with-classes reserved word approach to ‘this’ that differs from how a modern C++ compiler would implement keyword ‘this’.

DotThis is simpler than C++ approach. In TrapC:

  1. foo.Bar()Foo.Bar(&foo)as a member function call with explicit this parameter)

  2. .xthis->x (dot-this operator)

  3. this->xthis->x (explicit this arrow, same as above)

  4. Implicit this is just the first parameter of member functions

  5. ::x scoper is the scope resolution operator supported for C++ compatibility
  6. ..x is the same as ::x

TrapC uses dotThis, that is, a bare dot, whereas in C++, that would be this->. The bare dot is a shorthand notation available in TrapC.

Examples of these features.

// test_scoper.c

#include <stdio.h>

static int bar;

struct Foo 
{  int bar;
   int Bar()
   {  this->bar = 5; // Code compatible with C++
      return bar;
   }
};

int main() 
{   struct Foo foo;
    bar = 1;
    foo.bar = 2; // TokenDot followed by TokenIdentifier
    ..bar = 3;   // TokenDotDot followed by TokenIdentifier
    ::bar = 4;   // TokenScoper followed by TokenIdentifier 
    printf("bar = %i, foo.bar = %i, foo.Bar() = %i\n",bar,foo.bar,foo.Bar());
    return 0;
}

// test_dot_this.c

void Bar()
{  puts("Bar");
};

struct Foo
{  int x;
   int y;
   void SetX(int rhs)
   {  x = rhs; 
   }
   void SetY(int y)
   {  .y = y; // this->y = y
   }
   int GetSum()
   {  return .x + this->y;
   }
   void Bar()
   {  puts("FooBar");
   }
   void BarGlobal();
   void BarScoper();
};

void Foo.BarGlobal() // same as Foo::BarGlobal()
{ ..Bar(); // same as ::Bar()
}

void Foo::BarScoper();
{ ::Bar();
}

int main()
{  Foo foo;
   foo.SetX(10); // Foo.SetX(&foo, 10)
   foo.SetY(20); // Foo.SetY(&foo, 20)
   int sum = foo.GetSum(); // Foo.GetSum(&foo)
   printf("Sum: %d\n", sum);
   foo.Bar();
   foo.BarGlobal();
   foo.BarScoper();
   return 0;
}

 

Leave a Reply

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