Skip to content
CppCooperProgramming Portfolio

Article

Small C++ Programs for Small Questions

Architecture

Sometimes I want to try a piece of C++ before giving it a job inside another project. A small program is a convenient place to check syntax, inspect an unfamiliar facility or find out whether an assumption survives contact with an implementation.

My testing repository is a collection of those programs. It includes input, time tracking, compiler-generated names, stack tracing, stream redirection and filesystem experiments. They are prototypes gathered around particular questions, rather than one assertion-based test suite.

Which output are you actually redirecting?

The stream-toggle experiment gives four output paths their own small functions: stdout, stderr, std::cout and std::cerr. It calls each while output is disabled and again after restoring it.

One toggle saves the C++ streams’ original buffers and replaces them with a dummy std::streambuf. Toggling back restores the saved buffers. The other path uses freopen on the C streams, with Windows or Linux destinations selected by platform macros.

The distinction is the question. Replacing an object’s stream buffer and reopening a C stream operate at different interfaces. Keeping all four writes in the same little program makes that boundary visible without surrounding it with an application’s logging and window code.

A successful build can still give the wrong answer

Another experiment extracts type and class names from compiler-generated function-name strings. It has different parsing paths for MSVC and other compilers. A later GCC 16 smoke run completes, but some printed names are malformed or unexpected. The program running to completion does not make the string format a portable reflection interface.

The collection also uses supplied components, including POSH, StackWalker and a registry wrapper, with their source credits retained. Local adaptations need to be distinguished from those components themselves.

That is the scale I wanted from these experiments: a small enough program to see the mechanism being tried and the assumptions around it. Whether a prototype was later adopted, and how it behaved in its original Windows environment, are separate questions.