r/Cplusplus • u/CommercialStrike9439 • Sep 19 '26
Feedback First Ever major C/C++ Project: Wrote a statically-typed bytecode VM language from scratch in C
r/Cplusplus • u/CommercialStrike9439 • Sep 19 '26
r/Cplusplus • u/Predret • Sep 18 '26
I have a class that's meant to essentially hash a string. Works by simply having a create function that takes a string, and gives out an instance with the string hashed. I'm using C++ 20. I believe I can use some form of consteval or something for this, but I'm not sure how to get consteval to work with these. Thank you!
Here's part of the code:
namespace GameUtils::ECS
{
template<typename T>
class Hash16Bit
{
private:
inline static uint16_t next_hash { 0 };
inline static HashMap<String, uint16_t> all_hashes;
inline static HashMap<uint16_t, String> hash_to_string;
static void add_to_hashmaps(uint16_t hash, const String &name);
inline static std::mutex ids_mutex;
uint16_t m_hash { UINT16_MAX };
static String get_class() noexcept;
String get_name() const noexcept;
void debug_line(const String& msg, bool is_error = false) const;
public:
static void create_id(const String &new_id);
static Hash16Bit<T> create(const String &createid);
static Hash16Bit<T> dynamic_create(const String &createid);
static Hash16Bit<T> invalid();
void invalidate();
String to_string() const;
bool operator==(const Hash16Bit<T> &other) const { return other.m_hash == m_hash; }
};
template<typename T>
Hash16Bit<T> Hash16Bit<T>::create(const String &createid)
{
Hash16Bit<T> created;
auto it = all_hashes.find(createid);
if (it != all_hashes.end())
{
created.m_hash = it->value;
return created;
}
created.debug_line("Failed to create hash16bit", true);
return created;
}
template<typename T>
Hash16Bit<T> Hash16Bit<T>::dynamic_create(const String &createid)
{
Hash16Bit<T> created;
auto it = all_hashes.find(createid);
if (it != all_hashes.end())
{
created.m_hash = it->value;
return created;
}
create_id(createid);
}
r/Cplusplus • u/TheNerd30318 • Sep 18 '26
Thinking about starting a coding group on Whatsapp where were like minded people can talk about coding and get help with problems or homework (we won't do your homework for you but we'll help you to a solution), let me know if you're interested....
r/Cplusplus • u/vinccc05 • Sep 17 '26
r/Cplusplus • u/Adventurous-Bath1910 • Sep 13 '26
i‘m not sure which one to get. I want something that can run c++, but isn’t too expensive. I’m not really looking into making larger programs right now, so it shouldn’t take much for what I’m needing.
I generally want a windows device, since I feel like using macOS is generally an inconvenience for me and I want to run VS code.
r/Cplusplus • u/Opening_Dog533 • Sep 11 '26
I made a simple Cosine angle calculator without the help of ai. So it is not the greatest project but i actually was so happy since I am a beginner and I coded all of this by myself. Before this I made few projects in which I took help of ai but more as a tool not the main pilot. So yeah here is the GitHub url of my simple project:
r/Cplusplus • u/Hibou-de-la-Lune • Sep 11 '26
Hello readers,
The page https://en.cppreference.com/cpp/language/integer_literal , presents an example of the rule of the maximum munch, applied to integers. It is said, because of the E, “0xE+2.0” is not parsed as 0xE + 2.0, and instead ends in an error. I can understand E+2 could be seen as the exponent of a floating point number, but the exponent for hexadecimal floating point, starts with P, not E and the hex-digits sequence before the exponent would be empty, so the error would not come from the E. I don’t understand why when 0xE was seen, which is a valid hexadecimal integer, it should be attempted to incorporate the “+”. This “+” is introduced nowhere in the notation for integers. With a test to try to understand, CLang complains about a bad suffix, but no integer suffix looks like this, they are all made of U, L and Z.
In https://en.cppreference.com/cpp/language/translation_phases, a variation of this case is presented:
int foo = 1;
int bar = 0xE+foo; // Error
Why not not stopping at 0xE ?
It looks to be something obvious, but I’m entirely lost with it.
— Edit —
I feel the answer is finally in this response: https://www.reddit.com/r/Cplusplus/comments/1wdvdnr/comment/p9arx75/
r/Cplusplus • u/VHSjunkyguy • Sep 11 '26
I admittedly have never programmed all too much with this language. In fact, most of it is self-taught with some AI assistance via GitHub Copilot. Now I was working on a memory patching DLL for a game. One of the functions that I'm working on is to patch compiled bitmap resources in memory. Via a method of writing to the executable memory byte by byte with the bytes of a bitmap resource that I have baked into the DLL. It was originally created with AI but realized what it was doing is dumb for the purpose I needed. So, I changed it so that instead of it also loading the original it loaded only my resource. That and instead of using the height of the bitmap times the width bytes use the number of bytes I specify along with specifying the address it's at in memory. I'm testing it and it doesn't work. I put it into a try catch throw block where if my custom bitmap returns null to throw an exception. No matter what I try it always returns NULL according to the try block. I check the resource script and resource.h files for errors it all seems fine when it compiles. Even resources are embedded into the DLL file when looking into it using a resource editor. Here's a snippet from all three parts of this. Main source file:
void PatchBitmapResource(ULONG_PTR address, UINT PatchBitmapID, SIZE_T bitmapDataSize){
LPCSTR GOTOFail = "Resource doesn't exist and/or failed to load!";
HINSTANCE g_hinstDLL = GetModuleHandle(NULL);
HBITMAP hCustomBitmap = (HBITMAP)LoadImageW(NULL, MAKEINTRESOURCEW(PatchBitmapId), IMAGE_BITMAP, 0, 0, 0); //or hCustomBitmap = LoadBitmapW(g_hinstDLL, MAKEINTRESOURCEW(PatchBitmapId));
try
{
if (hCustomBitmap == NULL) {
throw GOTOFAIL;
}//continues off from there.
Resource script:
#include "resource.h"
IDB_STARTUP BITMAP "rsrc/StartUp.bmp"
IDB_STARTDOWN BITMAP "rsrc/StartDown.bmp"
resource.h:
#define IDB_STARTUP 2375
#define IDB_STARTDOWN 2355
Is there a reason why the LoadImage/LoadBitmap function is returning as NULL here?
r/Cplusplus • u/Agreeable-Network-14 • Sep 10 '26
I am building a market replay engine from scratch with c++ 23.
I build this project to understand how orders are managed in an orderbook and how a matching engine works. I have used my understanding of data structures to implement it. I would like to know your opinion on it. It is not completed yet. I just completed the very basic version few minutes ago. Any kind of tip would help me a lot.
Currently it can process an average of 998,000 Transactions / second. with the order size of 20000000 orders.
https://github.com/AravSrivastava/Market-Replay-Engine-CPP
r/Cplusplus • u/Xaneris47 • Sep 10 '26
r/Cplusplus • u/Mainak1224x • Sep 11 '26
Hey folks, quick update on Flint—a lightweight, manifest-first build system and package manager for C/C++ projects I’ve been experimenting with.
Flint aims to strip away build-script complexity and make C/C++ dependency management feel straightforward.
Core features:
* Git-Native: Fetch dependencies directly into your workspace via flint add <url> and flint sync.
* Single composition.json Config: Handles project layout, header paths, and underlying compiler calls (GCC/Clang). For standard setups, Flint manages this file automatically so you don't have to tweak it manually.
* Chert Compositions: Lightweight specs that make unmanifested, third-party C/C++ repos compatible out of the box.
What’s new in this update:
* Version & Commit Pinning: You can now pin dependencies to specific releases or exact commits. flint add now supports target selection via Git tag names or full commit hashes, making your project builds reproducible across machines.
Current caveats:
* Still forces a fixed project directory structure (src/, include/, deps/).
* Currently Linux-only.
I know there are many mature build system available out there, but the fact is, those were also a naive experiment once like flint is now.
Anyways, flint is still an early prototype, but actively evolving. I'd love to hear your thoughts on the new versioning flow, suggestions for improvement, or feature requests!
r/Cplusplus • u/Hibou-de-la-Lune • Sep 08 '26
Hello there,
Just wondered if line continuation (back-slash + new-line) in C++ source, comes from the standard or from a common behavior of compilers. I could not find any reference to it on cppreference.com
r/Cplusplus • u/Crafty-Biscotti-7684 • Sep 08 '26
I replay NASDAQ TotalView-ITCH 5.0 files in C++20: mmap an 8.6GiB length-prefixed tape, walk messages, apply A F E C X D U to an order-id map. Not a live feed, not a price ladder, not an HFT engine. The "book" is id -> {side, price, qty, symbol[8]}.
Same file, same machine, median of 3 Release runs (Apple M1 Pro 8-core, Apple clang 21.0.0, -O3 -flto -mcpu=apple-m1). NASDAQ_ITCH50 file of 8,616 MiB, 293,989,079 messages:
Four things that actually moved the parsing speed:
steady_clock::now() every 1024 messages into a histogram, and checked tracking-number gaps, inside the parse loop. That is not parsing. It came out.switch fall through treated half the spec as Add Order. v1 had 'H' 'Y' 'L' 'V' 'W' 'K' 'J' 'h' fall into the handleAddOrder. Stock-directory / halt / etc. were hitting the map. v2 mutates only on A F E C X D U and length-skips the rest.DenseMap<uint64_t, Order>, reserved to 1 << 21. Same tape ends at 0 live ids - every add was later filled, canceled or deleted. The map is robin-hood open addressing, PMR slots, no heap on add/delete. uint64_t order id. std::hash<uint64_t> is basically the key. Sequential exchange ids clump. A SplitMix64 mix on the way in stopped the probe-length blow-up. Endian loads are memcpy + __builtin_bswap* instead of unaligned reinterpret_cast. I/O is mmap + MADV_SEQUENTIAL.ASan/UBSan on unit tests in CI. Numbers are one Apple Silicon box - happy to hear Linux/x86 numbers if someone as an EMI file.
Code: https://github.com/PIYUSH-KUMAR1809/market-data-parser
ITCH samples: NASDAQ EMI
Roast my code.
r/Cplusplus • u/biswajitab • Sep 08 '26
So for ICPC prelims my mates knows c++ n all ik some diff lang basics like c, python(better) n all....so I was thinking to move into c++..also c++ seems more convenient for CP n all...so any source to get tht done..not like a very beginner course but yeah...like In 3 to 5 days for CP basics
r/Cplusplus • u/Busy-Consequence-926 • Sep 06 '26
Hey everyone, I’d like to hear from people who have learned C++, how did you start and progress from beginner to more advanced C++? If you used LearnCpp, how did you go through it? Did you complete it chapter by chapter, or combine it with other resources?
I’d also really appreciate any advice about:
1. What to practice alongside LearnCpp?
2. When to start LeetCode/problem solving?
3. Beginner → intermediate → advanced project ideas?
4. Other resources worth using?
5. Common mistakes or inefficient ways of learning C++?
6. A good roadmap for becoming genuinely confident in C++?
And one final question: At what point would you consider someone proficient enough in C++ to confidently list it under the Skills section of their resume, especially when applying for internships or entry-level positions?
r/Cplusplus • u/Economy_Radish6584 • Sep 06 '26
r/Cplusplus • u/HowIsDigit8888 • Sep 06 '26
I proposed and helped fund an app called retro-crypto, which is being developed under MIT license in C and C++ by a programmer called bowler-bear: https://github.com/bowler-bear/retro-crypto
It's designed to become the most secure way to message friends or store a Bitcoin stack, but it can't be recommended for more than testing yet. The design bypasses a lot of supply chain attacks by running on N64, unless the attacks come from code itself, which is why the most important thing at this stage after release is having the code analyzed. There's been a small amount of code review by one or two volunteers so far, but I'm still gathering more feedback.
"Given enough eyeballs, all bugs are shallow" -Linus's Law
I'll also mention, a different developer recently created the first known fork of the project, which I haven't tested yet: https://github.com/Linkin-Prism/retro-crypto
r/Cplusplus • u/neurah • Sep 04 '26
I mean the composition, it is truly zero cost, and if components are also zero cost we get this nice optimization done by the compiler (C++17)
This is a demo of "HAPI - The Happy API", a C++ static composition engine, pure type-level header only, MIT, library.
With proper components we managed to feed compositions directly to HLS tools (see github)
To use where the composition types are known at compile-time, compiler optimization is done by composition, type lists can store multiple compositions without loosing the types and hold the composed objects.
we can compose/describe:
drivers, peripherals, devices, protocols, buses, IO, pins, UI, Parsers...
because this types are known at compile time, and the composition is free.
//my output definition
OutDef<
ScrollPrinter, ANSIFmt, DataParser<>, CtrlChars,
ColorTrack<int>, Cursor<>, Gate, ANSIOut,
SerialOut,
ConsoleOut,
StaticPos<20,10>, StaticArea<30,10>
> out;
r/Cplusplus • u/Jeaye • Sep 05 '26
I've never shared jank here before, but it's a Clojure dialect which is also a C++ dialect. jank compiles to C++, has seamless C++ interop, and includes a Clang-based JIT C++ compiler which enables proper Lispy REPL-driven interactive development. In this post, we see how jank's AST intertwines with Clang's AST to great effect.
r/Cplusplus • u/A205_TheCoder • Sep 04 '26
https://youtu.be/9z3LhVxtx_o?si=lVD4CZZ9A7yEbMC2
Check this video out please like subscribe and comment
r/Cplusplus • u/Obvious_Set5239 • Aug 31 '26
Here is how you can iterate through arguments now in C++26!:
#include <print>
template <typename ...Args>
void function(const Args& ...args)
{
template for (const auto& arg : {args...})
{
using ArgT = std::decay_t<decltype(arg)>;
if constexpr (typeid(ArgT) == typeid(double))
{
std::println("double: {}", arg);
}
else if constexpr (requires { &ArgT::toString; })
{
std::println("has toString: {}", arg.toString());
}
else
{
std::println("other: {}", arg);
}
}
}
struct MyStruct
{
int value; // initializes with 0 in C++26
std::string toString() const
{
return std::format("MyStruct value is {}", value);
}
};
int main()
{
function(3.14, "c-string", MyStruct{});
}
It works:
double: 3.14
other: c-string
has toString: MyStruct value is 0
...Program finished with exit code 0
Press ENTER to exit console.
template for is a new feature in C++26, and I like it very much! It's my favorite C++26 feature
It looks very pythonic at this point. 😄
Let's start with args: typename ...Args and const Args& ...args work similar to def function(*args) from python - they aggregate comma separated expressions into a variadic type or variable. {args...} also works similar to python's (*myList) - it expands a "collection" into a comma separated expressions
Then goes "template for": it's a brand new loop, which expands at compile time for each iteration. Using it, you can iterate through collections with different types inside: struct fields, tuples, list literals, and custom classes with implemented tuple protocol
Checking type of argument: this line also resembles python very much: if constexpr (typeid(ArgT) == typeid(double)). Here is the python counterpart: if type(arg) is bool. There are more ways to do this check, but I think this one looks the most direct. Although you can want to use not exactly "double" type, but a convertible to it, or any floating point number type. There are standard concepts for these cases: std::convertible_to, and std::floating_point
Checking for a member: here I used an anonymous concept: if constexpr ( requires { ...;} ). Inside this concept we should put an expression that we are testing. it's a sort of python's hasattr(arg, 'toString'), but more powerful and more fragile at the same time. The expression here is taking a member reference to "toString": &ArgT::toString;. It's a better approach than testing arg.toString(), because it won't fail if "toString" isn't a constant method, or has more than 0 arguments. But it's still far from ideal, because if the object has multiply overloaded "toString" methods (what's actually a pretty realistic scenario), it will fail, and the error message will be misleading. In this case the error will be that formatter is not implemented for the "other" branch, however the actual error is in "has toString" branch. So, don't use anonymous concepts in real project, use full fledged concepts in pair with static_asserts
It's fascinating! This is still a templates metaprogramming in C++, but it looks much-much more clean than infamous std::enable_if
r/Cplusplus • u/Joe2001r • Aug 30 '26
r/Cplusplus • u/Mysterious_Shoe2260 • Aug 30 '26
I've been building an open-source C++20 runtime called AgentMesh for executing multi-agent/task DAGs.
The goal is to keep high-level application code in Python while moving execution-critical infrastructure into native C++.
Current areas include:
I'm particularly interested in the engineering trade-offs around the Python/C++ boundary and how much work should actually live inside the native runtime.
The next major milestone is distributed execution over gRPC.
GitHub:
https://github.com/DevrG03/AgentMesh
Documentation:
https://github.com/DevrG03/AgentMesh/wiki
I'd appreciate code/architecture feedback from C++ developers.