r/Cplusplus • • 7d ago

Subscriber Goal Welcome to r/​Cplusplus!

0 Upvotes

Welcome to r/Cplusplus

62215 subscribers / 75k subscribers. Help us reach our goal!

Visit this post on Shreddit to enjoy interactive features.


r/Cplusplus • • 15h ago

Discussion Updating 21 year old C++ software

33 Upvotes

This is just a dump of what I have been doing lately post. Feel free to discuss.

So I recently undertook the task of updating a piece of software that I designed and developed in 2005. It was first written in C++03 using QT 3.3.6 for the GUI. This ran on CentOS 4.3. Over the years as hardware and OS versions were refreshed it was updated to QT 5.9 but still the same logic written in C++03. Now we are on a system that supports C++23 and QT 5.15.

The software runs on all the nodes of our mid scale distributed systems. Acts as a control interface, status display and master logging software and site UPS interface so the system goes down properly when signaled. That is just a top level list of what is crammed into this this one piece of software. Oddly enough it was meant to just display the status of the system in a simple red or green set of indicators. Yeah, scope creep got the better of this one.

Myself and others have hacked in new functionality, updated other functionality and removed old stuff over these 21 years. However, we have kept to the logic patterns that were laid down in C++03. Which is to say this was more C with classes than pure C++. But a lot of C++ in 2005 was still C with classes. It was just the times. Interesting side note: We practice a form of obsoleting code that does not delete old code. It gets commented out and the new code is under it and comments explain why the change was made. So there is 21 years of this stuff commented out. Yeah finally deleting that stuff as this is going to be new major version.

So I have been rebuilding the program as a modern C++23 app using QT 5.15 as the GUI. Moved from a bunch of global variables to a shared data object. Making the app a data driven system that can run headless now if needed. Configs have moved from custom text file format to JSON. A lot of custom stuff executed by script files called by systems calls has been moved from hard coded to part of the JSON data.

So far I have pruned over 4000 lines of code, added about 2000 lines, rewritten around 5000 lines, removed entire classes and redesigned how the app works underneath without changing the GUI appearance which the customers are very use too. Networking has moved from broadcast UDP ( i don't remember why it had to be that way 21 years ago but there was a tech reason) to Multicast. It has been a wonderful journey so far. The challenge is when we drop it in it has to do everything it did before and be a seamless update. So offline testing is going to be extensive.

Things I knew already and this effort re-enforces. 1. Careful with what you write it will come back to haunt you. 2. There is never enough comments. 21 year is a long time and I just don't remember some of the original reasons for things to work certain ways. 3. Software Life Cycle Support can be rewarding and a curse at the same time.

After 35 years of software engineering and systems engineering specializing in mid to large scale distributed systems I can say it never gets boring. At least it is not ADA and COBOL anymore that I work on.


r/Cplusplus • • 22h ago

Discussion Guys help

1 Upvotes

iam going to attend the infosys exam in 2 weeks but iam only able to solve easy questions in leetcode but .There they will be asking medium to hard questions (3 question to be solved in 3 hrs) .atleast 2 i need to solve to pass .SO CAN YOU GUYS TELL ME WHAT TOPICS CONCEPTS SHOULD I NEED TO COVER ANY TIPS (C++)


r/Cplusplus • • 1d ago

News Day 2 of learning c++

Thumbnail
gallery
56 Upvotes

Day 2~ so far it's going good , made some basic progress, got to know about global/local variables,if/else statements;blocks, switch cases with the help of which I made myself my first basic calcultor , but the best one is probably the use of "cin" . Found out I can do much more with cin. Turns out floats are pretty useful too


r/Cplusplus • • 1d ago

Feedback My progress in learning CPP. Had fun learning basic classes.

Thumbnail
gallery
67 Upvotes

Hello guys,

Sharing my learning cpp daily progress---Basic classes. This is my work/mini project for the basic classes Chapter as well as making my own round function, and also improving my exponent function from last time. I also took everyone's advice regarding naming convention, and followed some, but I don't know if did everything right.

It took me 30 minutes with my TI to come up with an idea on how I would do a round function. At first, as was looking at recursion approach, but i think its not that necessary plus it could take up a lot of memory. I know you guys would say that "I could have just used the library", well as a beginner I really wanna come up with solutions on my own, and enhance my analytical ability while taking the challenge of learning C++.

I am all ears for all those who have suggestions/feedbacks. I am willing to learn. For anyone asking if i am still using that book---yes I am. Though I took the initiative to cross check everything I encounter.

I used NO AI whatsoever. Followed the book and used wikipedia, w3school, and cppreference (as for ShishRobot2000s' advice).

For now, the round func will be limited to unsigned short max limit of around ~65k. but as per logic wise, it will work.

Employee.h

#pragma once

class Employee
{

public:
Employee(unsigned short age, unsigned short yearsOfService,
unsigned short salary) :
_age(age), _yearsOfService(yearsOfService), _salary(salary)
{ }

unsigned short getAge() const { return _age; }
unsigned short getYearsOfservice() const { return _yearsOfService; }
unsigned short getSalary() const { return _salary; }

void setAge(unsigned short age);
void setYearsOfService(unsigned short yearsOfService);
void setSalary(unsigned short salary);

void reportSalary() const;

~Employee() { }

private:
unsigned short _age;
unsigned short _yearsOfService;
unsigned short _salary;
};

Employee.cpp

#include "employee.h"
#include <iostream>

unsigned short exponent(unsigned short x, unsigned short n)
{
if (n == 1)
return x;
else if (n == 0)
return 1;
else
return x * exponent(x, n - 1);
}

unsigned short round(unsigned short number, unsigned short place)// PLACE IS FOR DIGIT PLACE VALUE
{
unsigned short placeVal = exponent(10, place);
unsigned short nextDigit = (number / (placeVal/10)) % 10;

if (number < 1'000) return number;

if (nextDigit > 4)
{
number /= placeVal;
++number;
return number * placeVal;
}
else
{
number /= placeVal;
return number * placeVal;
}
}

void Employee::setAge(unsigned short age) { _age = age; }
void Employee::setYearsOfService(unsigned short yearsOfService) { _yearsOfService = yearsOfService; }
void Employee::setSalary(unsigned short salary) { _salary = salary; }

void Employee::reportSalary() const
{
std::cout << "\n\n**** Total employee report ****\n";
std::cout << "Age:\t\t\t" << _age << '\n';
std::cout << "Years of Service:\t" << _yearsOfService << '\n';
std::cout << "Salary:\t\t\t" << _salary << '\n';
std::cout << "Total Salary:\t\t" << round((_yearsOfService * _salary), 3);
}

Main.cpp*. Just paste this block into main*

{
Employee Mark(19, 1, 2'700),
Derk(30, 12, 3'400);

Mark.reportSalary();
Derk.reportSalary();
}

r/Cplusplus • • 1d ago

Question C++ and Data structure

Thumbnail reddit.com
1 Upvotes

r/Cplusplus • • 1d ago

Question How can I make a snake game in C++?

16 Upvotes

So for a project, I have to make a snake game and I'm completely lost. It doesn't have to be good graphics but my resources are limited to text output. I have visual studio 2022 and I also have online ide's. Any guidance will be helpful


r/Cplusplus • • 1d ago

Question Where to start with learning C++?

Thumbnail reddit.com
6 Upvotes

r/Cplusplus • • 2d ago

Tutorial Day 3 of learning c++

Thumbnail reddit.com
0 Upvotes

r/Cplusplus • • 2d ago

Discussion Fast C++ Compiler Update

Thumbnail
reddit.com
2 Upvotes

r/Cplusplus • • 2d ago

Question Transpiler for simplified C++

Thumbnail reddit.com
1 Upvotes

r/Cplusplus • • 2d ago

Feedback Started learning CPP. Hello World! :)

Thumbnail
gallery
103 Upvotes

Just started learning CPP by following the book i found in my dad's bookshelf. Its old and it have been printed from the 2000s. He has his name and date written on the date of purchase; 9th May 2000.

This is my exercise for the chapter tackling functions. I wrote a exponentiate function recursion. I got it hard at first and looked at the different examples from the book multiple times till i get it how i do exponents without loops. With a little bit of function polymorphism/overloading

Tbh, the book looks very weathered, its ancient. Most of the programs and code examples have been deprecated, so I just looked it up online what its modern approach. But the lessons taught are still relevant to todays standards.

Planning to read Modern CPP after finishing this.

Using Visual Studio for ease of use compiler wise. But I will move my learning journey to my linux setup after this to get a better feel for compilers and also Cmake.

NO AI is used to make this code nor supplement it---I just read the book. "It looks clean", yea because its my exercise project, the mess of it lives in the CPP_LEARNING_00 project as you can see in the solution explorer.


r/Cplusplus • • 2d ago

Question wanna get into sfml.

Thumbnail reddit.com
0 Upvotes

how do i start coding in sfml? which version is the best? i want to use visual studio but i don't like how hardware expensive it is and that it doesn't give easy descriptions of code before i use it. I think using code::blocks is good for me but i want to hear your opinion on which IDE i should use.

Also what is best i start learning using sfml? i already know basic things like shapes, .move, keyboard commands, and textures but where to learn more physique base code and make games similar to factorio and rollercoaster tycoon, sandbox games with a lot of work bts.


r/Cplusplus • • 2d ago

Feedback Chess AI in C++

Thumbnail
github.com
2 Upvotes

r/Cplusplus • • 3d ago

News Day 1 of C++

Thumbnail
gallery
308 Upvotes

What a easy startup to my first language. Got to know about data types , variable , strings , comments , Boolean seems fun and can't wait to find out more . Anyone got any beginner tips for me , would love to have some as a beginner


r/Cplusplus • • 3d ago

Feedback CMake kept breaking on me, so I built a zero-config C++ build system called HelpMake

0 Upvotes

Hey everyone,

I hit a wall of absolute frustration trying to get CMake working. I kept running into errors like "CMakeCache.txt not found", the syntax felt overly complex, and sometimes it was just completely unreadable.

Instead of switching to Meson or Bazel, I decided to build my own lightweight alternative. It's called HelpMake (hm), and I built it to fix the exact problems I was having. I would love some honest feedback from people who also get frustrated with modern build systems.

The Core Idea: Zero-Config & One Screen

I wanted a build system that didn't require a 50-line boilerplate just to compile a "Hello World" project.

With HelpMake, you don't even need a build file to start. You drop the binary into any C++ project folder, run hm -b, and it auto-detects your compiler, standard, source files, and includes. If it sees #include <thread>, it automatically links -pthread.

If you do want control, you write a HelpMake.txt that fits entirely on one screen. No hidden scripting languages. It looks exactly like what it does:

Compiler: g++
Version: std=c++20
Output: build/app

InputFiles {
    src/**/*.cpp # built in recursive glob
}

Flags {
    !cl: -Wall
    win: /W4 /EHsc
    linux: -Wextra -pthread
    mac: -Wextra
    clang: -Weverything
}

Why it feels different from CMake

I focused on building features that solve CMake's daily annoyances, not just implementing a spec.

  • No if(WIN32) blocks: You can put platform conditionals (win:, linux:, mac:) on any line. One config for every OS. You can also do it for a compiler (gcc:, clang:, cl:) or for any binary program or any file using the ? prefix (?mold:, ?file.cpp:, ?git:). You can also use ! (!win:, !?git:, !?file.hpp:) Examples:!win: ?mold: Linker: mold PreBuild { ?git: echo Git was not found !win: echo Windows isnt supported } Flags: { !gcc: ?file.hpp: ?main.cpp: !apple: ?clang: clang: -Weverything # this works xD }
  • C++20 Modules actually work: It scans your files, builds a dependency graph, and compiles modules in the exact right order automatically.Modules { src/math.cppm src/graphics.ixx # Thats it. HelpMake does the rest automatically }
  • The Task { } block: Need to run npm install, generate code with Python, or run a CMake script for a submodule? You can do it natively. No weird CMake macros. It just runs the shell commands you specify. e.g.Task: build_web { Check: web/package.json Generate: web/dist/bundle.js npm install npm run build }
  • Dependencies: You can pull in third-party libraries directly from GitHub with automatic caching.Dependency: fmt { Git: https://github.com/fmtlib/fmt Tag: 10.1.1 Include: include Build: cmake -B build }Config: app { Depends: fmt InputFiles { src/main.cpp } }
  • Zero Dependencies: It's a single ~50KB standalone binary. No Python, no Java, no CMakeCache. Just download it and run it.
  • Editor Support: Generate compile_commands.json instantly with hm -b --json.
  • Generator: Generate config files for cmake or ninja.
  • Automation: Automatically detects values that aren't mentioned:

    • Modules
    • Output name
    • Source Files
    • Include dirs
    • Compiler
    • Version
    • Kind (static or executable)
    • Link flags

Why am I sharing this?

I've seen a lot of people complaining about CMake, and I wanted to build something that just works. I would genuinely appreciate your brutally honest feedback on the design, the syntax, or the code.

It's MIT licensed and available for Windows, Linux, and macOS.

Repo: https://github.com/Gag91/Help_Make
Website & Docs: https://gag91.github.io/HelpMake/

If it save you times, feel free to leave a ⭐ !
I will try to respond to all of your questions/feedback, if you find any issue either make an issue or tell me out 😄.
Thanks for checking it out!


r/Cplusplus • • 4d ago

Question C++ systems route,will start building redis from scratch as a project,any guidance will be appreciated

Thumbnail reddit.com
1 Upvotes

r/Cplusplus • • 5d ago

Question Designing a C++ ML library from scratch — would you prefer A.transpose() or transpose(A) or A.T()?

Thumbnail reddit.com
2 Upvotes

r/Cplusplus • • 5d ago

Question New MPC SDK

Thumbnail
github.com
1 Upvotes

Quick question from a noobie dev and also part time audiohead, is this new sdk up to task with building plugins or is it just hype from inline music? Seems.no one is even interested about its release esp as it falls outside the realms of audio and electronic music. (Also vice versa as most devs probably have little interest in electronic music creation (I might be wrong)). As someone caught in the midst of both worlds I never touched an sdk so if someone more experienced could have a look and give an expert opinion on it would be much appreciated.

Github: https://github.com/inmusic-software/mpc-plugin-builder-sdk

Video: https://youtu.be/b6j-yfBVCv8


r/Cplusplus • • 5d ago

Question Difference to r/cpp ?

22 Upvotes

Hello, what is the difference between this subreddit and r/cpp? I saw an ad and joined here today. Thanks in advance


r/Cplusplus • • 7d ago

Question Drogon C++ web framework, Anybody out there using it ? what do you think of it ?

Thumbnail
reddit.com
6 Upvotes

r/Cplusplus • • 8d ago

Discussion Omnissiah++: когда русский C++ оказался недостаточно еретическим

Thumbnail
reddit.com
0 Upvotes

r/Cplusplus • • 8d ago

Discussion Introducing JaiScript a New C++ Embedded Scripting Language

23 Upvotes

This is a personal project I created in service of my own 2d game engine. I was getting tired of binding to ChaiScript (a great project, but the language is really slow and doesn't have hotreload or good serialization support) and Cereal (another great project, no complaints, just limited in its purpose.)

So, I rolled my own solution which combines a scripting language, serialization, and reflection. I included my own signals library and a simple but useful custom test framework.

JaiScript has a fluent binding interface, strong typing (opt-out with var definitions), value semantics with references and shared_ptr where you want them. It reads very much like C++ with some optional alternative spellings that will be familiar to those who use JavaScript.

The live demos on the site itself mean you can try it out before downloading or building anything locally. I already was able to fully port my game project of 12+ years to use this in place of ChaiScript and Cereal, it builds a little faster than both of those included and runs orders of magnitude faster than Cereal.

Performance-wise it runs roughly 1.2x to 2.0x slower than Lua's VM, I consider this a win though since it's hundreds of times faster than ChaiScrpit's tree walker in some cases. It runs faster typically than Squirrel.

I'm not sure how many folks are rolling their own C++ game engines nowadays, but if you are, this is a pretty full-featured language. It supports parallel_for (something I'm not sure any other scripting languages support,) coroutines, classes which can derive from C++ base classes or other JaiScript classes, and notably a state-preserving hot reload.

I hope this project is useful to anyone else, but even if not, I'm grateful to have finished the project and am using it myself. I wanted a place to share it, so hope this is alright here!