This document describes configuring a development environment for modern C++. Some of the flags and warnings in this document are not common knowledge, or found in the documentation of the respective toolchain.
Below is the compiler configuration we'll use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// clang-format off | |
#include <gcc-plugin.h> | |
#include <context.h> | |
#include <plugin-version.h> | |
#include <tree.h> | |
#include <gimple.h> | |
#include <tree-pass.h> | |
#include <gimple-iterator.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// clang-format off | |
#include <gcc-plugin.h> | |
#include <context.h> | |
#include <plugin-version.h> | |
#include <tree.h> | |
#include <gimple.h> | |
#include <tree-pass.h> | |
#include <gimple-iterator.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digraph state_machine { | |
rankdir=LR; | |
size="8,5" | |
node [shape = doublecircle, style=filled, fillcolor=lightblue]; WaitingForQuery; | |
node [shape = doublecircle, style=filled, fillcolor=maroon] GotErrorResponseDuringSimpleQuery; | |
node [shape = circle, style=filled, fillcolor=lightgrey]; | |
InitializingBackend -> GotCommandComplete [ label = "PG3ReadyForQuery", color=green ]; | |
InitializingBackend -> InitializingBackend [ label = "PG3BackendKeyData", color=orange ]; | |
GotDataRow -> GotErrorResponseDuringSimpleQuery [ label = "PG3ErrorResponse", color=red ]; | |
GotDataRow -> GotCommandComplete [ label = "PG3CommandComplete", color=green ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AuthenticationOk": { | |
"type": "backend", | |
"fields": [ | |
{ | |
"name": "Byte1('R')", | |
"type": "Byte1", | |
"description": "Identifies the message as an authentication request.", | |
"value": "'R'" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regex for lines like "Terminate (F)" | |
// Where the first group is the name of the message and the second is the kind (Backend/Frontend) | |
const pgMessageTypeRegex = /^(?<command>\w+) \((?<kind>\w)\)$/gm | |
// Regex for the type of a variable, like: | |
// - Int16, Int32, Byten, Byte4, String | |
// - Byte1('S') | |
// - Int32(4) | |
// - Int16[N] | |
// Where: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "node:fs" | |
const postgresWireProtocolDocs = ` | |
AuthenticationOk (B) | |
Byte1('R') | |
Identifies the message as an authentication request. | |
Int32(8) | |
Length of message contents in bytes, including self. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by blah blah blah | |
public class PostgresTypes { | |
public static class Backend { | |
public static class AuthenticationOk { | |
/** Identifies the message as an authentication request. */ | |
byte field1_Byte1 = 'R'; | |
/** Length of message contents in bytes, including self. */ | |
int field2_Int32 = 8; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <atomic> | |
#include <cassert> | |
#include <cstdint> | |
#include <cstdio> | |
#include <optional> | |
// A word-aligned, atomic tagged pointer. | |
// Uses both the upper 16 bits for storage, and the lower 3 bits for tagging. | |
// | |
// 64 48 32 16 |