r/cpp 8h ago

Ordering of qualifiers

4 Upvotes

I know this is something that pops up quite often, but I was wondering if I could get your guys' opinion on a fixed ordering of qualifiers. This is my current thoughts after recently trying to formalize my personal style:

static -> thread_local -> inline -> constexpr -> friend -> virtual

My reasoning for each:

  1. static first. Inside a class, its basically javas static. There is a pretty strong consensus in java for static first. Its very important context, for both functions and variables. Outside of classes, its more of a linkage specifier, which is arguably more important/nasty if you mess it up. The fact that it has this dual behaviour in C++ in my opinion makes an even stronger argument for including it first, your brain is able to parse it first thing. i.e okay this is static, we are in a class? -> its java static, we are in global scope -> its static linkage.
  2. thread_local directly after static, and then inline, then constexpr/consteval. This way, qualifiers which impact storage and or linkage are stuck together. I personally like to write inline even for constexpr/consteval functions, as its sometimes easy to forget the implicit inline. I used to do this for member functions with definitions in the class, but I feel the implicit inline there is a bit more well known/easier to intuit.
  3. The rest I'm far less opinionated on, since I barely ever use inheritance or the friend keyword. . I could go both ways on virtual/friend, so i default to alphabetical/aesthetics.

What do you guys think? I know this is pedantic and a very well explored topic but I wanted to know if you guys had any particular wisdom to sway me either way, mainly on the ordering of the first few.


r/cpp 6h ago

Partial application of class templates

Thumbnail elbeno.com
5 Upvotes

r/cpp 1h ago

I built Uranium: A statically typed language with a hand-rolled x86_64 JIT (no LLVM) and generational GC in modern C++

Upvotes

Hey everyone,

I wanted to share some architecture insights from a large hobby project I have been developing in modern C++ (C++17/20): an execution environment and compiler runtime called Uranium.

Rather than wiring up heavy third-party backends like LLVM, the goal was to build the entire systems layer directly in C++ to understand execution mechanics at the hardware level.

Key C++ architecture details:

  1. JIT without external libraries (src/native_jit_x64.cpp): Implemented a lightweight assembler in C++ that allocates executable pages (VirtualAlloc on Windows, mprotect on POSIX) and emits raw x86_64 opcodes directly for hot numeric loops and branch patching. It detects hot execution paths via loop back-edge tracking in the interpreter dispatch loop.

  2. Generational GC and Memory Management (src/heap.cpp): Instead of generic smart pointers or standard allocators, memory is managed through an anti-fragmentation object pool using placement new. It features a two-tier generational Mark & Sweep (young nursery vs full sweep) guarded by pointer write barriers (writeBarrier) to maintain remembered sets.

  3. Concurrency & Native Subsystems: Built a cooperative async task scheduler, custom socket abstraction for raw TCP, and embedded SQLite3, all unified within the C++ runtime.

Repository: https://github.com/bruhgit/Uranium-Programming-Language

I would love to get feedback on the modern C++ idioms, memory layout, or any potential architectural bottlenecks from fellow C++ systems developers!


r/cpp 6h ago

Optimizing a Spin-Lock

Thumbnail david.alvarezrosa.com
32 Upvotes

r/cpp 6h ago

Lazy Evaluation

Thumbnail breese.github.io
3 Upvotes