fun-plus-plus: Writing C++ Using Only c and ++

A short diversion into C++ naming rules, operator sequencing, and the joy of being literal.


The Premise

What is C++? Literally: c followed by ++.

So what happens if you write a C++ program where the only identifier is c and the only operators are ++ and +=? That is the question fun-plus-plus answers.

The source file is named c++.cpp. It compiles cleanly with both g++ and clang++. It does something.


The Code

#include <stdio.h>
int c(int c) {
    return ++c += c++;
}
int main() {
    int c = ::c(c++);
    printf("c++=%d", c++);
}

Every identifier is c. The function is c. Its parameter is c. The local variable in main is c. The global scope operator :: is the only way to tell the function call apart from the variable.

The format string "c++=%d" contains the literal text c++. The argument is c++. Even the output is on-theme.


What Does It Actually Do?

Inside c(int c):

++c += c++ looks like undefined behavior from the C era, but C++17 changed the rules for compound assignment: the right-hand operand is sequenced before the left-hand operand. So the evaluation order is well-defined:

  1. c++ — reads the current value of the parameter (call it n), then increments c to n+1. Yields n.
  2. ++cc is now n+1; pre-increment brings it to n+2. Yields the lvalue c (now n+2).
  3. (n+2) += n — adds n to c, giving c = 2n+2.

The function returns 2n+2.

In main():

int c = ::c(c++) initializes c by calling the function with c++. The local variable c is read before it is initialized — which is technically undefined behavior. In practice, on Linux, the fresh stack frame for a small program like this contains zeroed memory, so c is 0, c++ passes 0, and ::c(0) returns 2.

printf("c++=%d", c++) prints c++=2, then increments c to 3.

Run it yourself:

git clone https://github.com/32bitmicroLLC/fun-plus-plus
cd fun-plus-plus
bash build-ad-run.sh

Why This Is Worth Three Minutes of Your Life

Embedded C++ engineers spend a lot of time reasoning about sequencing, initialization order, and the gap between "this compiles" and "this is defined." The fun-plus-plus program is a stress test for exactly those intuitions — wrapped in a joke small enough to hold in your head all at once.

It also illustrates something useful: C++17's sequencing improvements made real code safer, but they also made clever-bad code more predictable. ++c += c++ is well-defined in a C++17-compliant compiler in a way it never was in C or earlier C++ standards.


Try It

The repository is at github.com/32bitmicroLLC/fun-plus-plus. MIT licensed. Takes about 30 seconds to clone and run.

If this kind of low-level reasoning is relevant to your project — perhaps with fewer jokes and more production firmware — get in touch.

Copyright © 32bitmicro, LLC 2024-2026