Bazel for C++ development
I predominantly write go/java/python code. So bazel is a great way for me to manage all of my toolchains and dependencies when developing/building/deploying on arm64 Mac or x87_64 Ubuntu. I’ve been working on porting some of my go code to c++ for both learning purposes and potentially performance gains.
Has anyone worked with bazel and c++? What has your experience been? Would love some pointers/tips.
https://redd.it/1h67uvd
@r_cpp
How to get a timestamp inside a thread
I have a script where I generate a thread that collects data and I would like to put a timestamp on it. I tried using the std::chrono library but for what I discover calling system_clock::now() is not thread safe, it always returns the same stamp, while if I use the steady_clock::now() it gives an increasing stamp, but is not referenced to the epoch.
I also tried to declare the stamp variable as atomic and modifying it in the main loop, to later use it from the thread but I got the same behavior: a stuck number. Using mutex to lock the use of variable also results in the same behavior.
btw if someone wants to tell me if I am stepping in the good direction: I am interested in millisecond resolution, I will be collecting data each 0.5s, but I need a good timestamp to correlate that data with some data that is taken by another instrument. Both system will be referenced to the same NTP server (we have our own timeserver).
https://redd.it/1h5xnrm
@r_cpp
Any primary C++ developers working in golang?
I have 10+ years of experience in C++, last few years 2+ I have been working in Golang. Things I miss from C++ STL, CompileTime Programming, generics , immutability a truly const, strong enums, better error handling. Things I wish C++ had which golang has goroutines, channels, ease of writing unit tests, a easier learning curve with lot less sharp edges.. If given a chance I will switch back to c++ in a second. Any one else have similar experiences with golang?
https://redd.it/1h5rl0x
@r_cpp
Sebastian Theophil: Passive ARM Assembly Skills for Debugging, Optimization (and Hacking)
https://youtu.be/uyIEg0HkWrQ
https://redd.it/1h5jglp
@r_cpp
Post-Wrocław update: Plans for the next quarter or two
https://github.com/hsutter/cppfront/discussions/1345
https://redd.it/1h520mf
@r_cpp
New C++ Conference Videos Released This Month - December 2024
CppCon
2024-11-25 - 2024-12-01
C++ Coroutines and Structured Concurrency in Practice - Dmitry Prokoptsev - [https://youtu.be/aPqMQ7SXSiw](https://youtu.be/aPqMQ7SXSiw)
Hidden Overhead of a Function API - Oleksandr Bacherikov - https://youtu.be/PCP3ckEqYK8
What’s Eating my RAM? - C++ Memory Management - Jianfei Pan - [https://youtu.be/y6AN0ks2q0A](https://youtu.be/y6AN0ks2q0A)
Back to Basics: Debugging and Testing in C++ Software Development - Greg Law & Mike Shah - https://youtu.be/ghurTk\_A-Bo
Back to Basics: Function Call Resolution in C++ - Ben Saks - [https://youtu.be/ab\_RzvGAS1Q](https://youtu.be/ab_RzvGAS1Q)
C++OnSea
2024-11-25 - 2024-12-01
Time Travel Debugging - Debug Complex C++ Bugs With Software from Undo - Mark Williamson - https://youtu.be/fkoPDJ7X3RE
Testable by Design - How to Create Testable C++ Code Using C++ Language Features - Steve Love - [https://youtu.be/0\_RMB6gL6WI](https://youtu.be/0_RMB6gL6WI)
Allocator-Aware C++ Type Design - Jonathan Coe - https://youtu.be/hZyJtRY84P4
ACCU Conference
2024-11-25 - 2024-12-01
Lightning Talk: CO Routine - Computing Dad Jokes - Chris Oldwood - [https://youtu.be/jDLiYj3tHVg](https://youtu.be/jDLiYj3tHVg)
Lightning Talk: The XZ Backdoor and a 40 Year Old Prediction - Christopher Harpum - https://youtu.be/AzfKTpkml\_I
Lightning Talk: Naval Applications of the C Programming Language - Guy Davidson - [https://youtu.be/y3Y5YxzsY08](https://youtu.be/y3Y5YxzsY08)
CppNorth
2024-11-25 - 2024-12-01
Splatty! A Gaussian Splatting Viewer for Everyone! - Pier-Antoine Giguère - https://www.youtube.com/watch?v=EDzvJmnyuPU
Hiding your Implementation Details is Not So Simple - Amir Kirsh - [https://www.youtube.com/watch?v=JY60-P1tYOw](https://www.youtube.com/watch?v=JY60-P1tYOw)
To Int or To Uint - Alex Dathskovsky - https://www.youtube.com/watch?v=F\_peBmYPRYw
Meandering Through C++ Creating ranges::to - Rudyard Merriam - [https://www.youtube.com/watch?v=miQiMn\_s0JI](https://www.youtube.com/watch?v=miQiMn_s0JI)
Keynote: Advent of Code, Behind the Scenes - Eric Wastl - https://www.youtube.com/watch?v=uZ8DcbhojOw
C++ Memory Model: from C++11 to C++23 - Alex Dathskovsky - [https://www.youtube.com/watch?v=tjcU2xDmuFQ](https://www.youtube.com/watch?v=tjcU2xDmuFQ)
Simplify and Secure Equation Systems with Type-Driven Development - Arne Berger - https://www.youtube.com/watch?v=eOoqVp5NTeU
https://redd.it/1h512ju
@r_cpp
Framework for modern interface
I have to modernize a relatively old, larger program (Windows) from the B2B sector. Unfortunately, this is based on a framework that has not existed for several years.
The goal is to have a future-proof, modern user interface. The ideal case would be if it could also be ported to MacOS, but it's not a must.
Now the question arises as to which current framework would be best for this. Years ago I did something with WxWindows, but at least back then it was more practical.
QT is often recommended, but it is not yet clear to me whether it is good for the area of application (many input masks, evaluations, dashboards).
But maybe you have other ideas as to what would be more suitable.
An additional question. The program currently integrates a browser plugin (internal PHP interpreter, including HTML representation in the plugin) to display some smaller tools within the program. The advantage was that it was quicker to create and that you could also hire web developers to do it.
Is something like this still relevant in current frameworks or would you all convert these tools to C++?
https://redd.it/1h4q29g
@r_cpp
Hi, i have problem her Debuger Error!
It says:
abort() has been called
(Press Retry to debu the application).
I need help.
Thanks.
https://redd.it/1h4q9mb
@r_cpp
Problem with compiler
Hello everyone!
I'm starting to learn C++ (second time lol), and i already have a problem.
When i try do compile any .cpp file, in cmd or even on VSCode for example, i receive this error:
"as.exe - Entry Point Not Found
The entry point for the procedure ZSTD_compressStream2 could not be located in the dynamic link library C:\\msys64\\ucrt64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\14.2.0\\..\\..\\..\\..\\x86_64-w64-mingw32\\bin\\as.exe."
I used this tutorial to install msys2 : https://code.visualstudio.com/docs/cpp/config-mingw
Could anyone help me? 😢
https://redd.it/1h4kl80
@r_cpp
Is this a good project?
So, i git the idea to make a desktop app for converting different file formats, like png to jpeg or pdf to word. I know there are libraries like libpng or libjpeg that can do most of the heavywork in the convertion but i really think it would be really god to for learning if i create my own implementations, right now i’m reading a document from W3 about png and exactly hiw it works, its being a bit of a mess and i’m struggling a bit in the understanding of the concepts but i think it will teach me many things.
https://redd.it/1h4eekm
@r_cpp
Coroutines promise type
Hi there,
I've recently learnt about coroutines, and got excited as I maintain several async libraries, for which to support coroutines for at least the base library -the task scheduler-.
The task scheduler serves bare functions: No parameters , no return value, and I want to keep it as it is while supporting coroutine to coawait for periods, primarily.
Therefore I went to have the promisetype::getreturnobject() to return void, as no intention to enforce application/user to switch such tasks to different function signature, and to avoid double managing the tasks.
I've initially implemented that, with a compile error preventing me to proceed: error: unable to find the promise type for this coroutine
.
Following is the main implementation of the coroutine, and here's the execution link: https://godbolt.org/z/4hWce9n6P
Am I getting coroutines wrong? What is suggested to do?
Thanks.
class H4Delay {
uint32_t duration;
task* owner;
task* resumer=nullptr;
public:
class promise_type {
task* owner=nullptr;
friend class H4Delay;
public:
void get_return_object() noexcept {}
std::suspend_never initial_suspend() noexcept { return {}; }
void return_void() noexcept {}
void unhandled_exception() noexcept { std::terminate(); }
struct final_awaiter {
bool await_ready() noexcept { return false; }
void await_suspend(std::coroutine_handle<promise_type> h) noexcept {
auto owner = h.promise().owner;
if (owner) owner->_destruct();
task::suspendedTasks.erase(owner);
// [ ] IF NOT IMMEDIATEREQUEUE: MANAGE REQUEUE AND CHAIN CALLS.
}
void await_resume() noexcept {}
};
final_awaiter final_suspend() noexcept { return {}; }
};
std::coroutine_handle<promise_type> _coro;
H4Delay(uint32_t duration, task* caller=H4::context) : duration(duration), owner(caller) {}
~H4Delay() {
if (_coro) _coro.destroy();
}
bool await_ready() noexcept { return false; }
void await_suspend(std::coroutine_handle<promise_type> h) noexcept {
// Schedule the resumer.
resumer = h4.once(duration, [h]{ h.resume(); });
_coro = h;
_coro.promise().owner = owner;
task::suspendedTasks[owner] = this;
}
void await_resume() noexcept { resumer = nullptr; }
void cancel() { ... }
};
Easy 2d Engine
Hey guys, I’m learning C++ for Uni and we have to make a chess themed program in the end (1st semester). As I’m not good in chess I wanted to do a pixel art 2d chess app and tried VS for it but as I’m still learning cpp I have trouble working with the desktop wizard. Is there any 2d engine with an relative easy to learn framework?
https://redd.it/1h48y1d
@r_cpp
Advent of code 2024 in modern c++
Day 01, part1 and part2 solution
https://github.com/d-ranjan/AdventOfCode2024/tree/main/day01
https://redd.it/1h465l3
@r_cpp
Unknown Error in CPP
I recently been trying to learn cpp and to try and expand my skills I attempted to create a hangman program. But after a while I got a strange error which I don't know how to fix.
Here is the error in the code and what I'm trying to fix ( The error is above the arrows )
void correctguess(){
blankwordscanned_letter == inputedletter;
^^^^^^^^^
}
This is the consoles output, The 'blank\word' variable is just the blank word placeholder and is equal to and printed in the console as ' _ _ _ _ _ '.
+---------------------------------+
| Hang Man |
+---------------------------------+
| | |
| | |
| 0 |
| /|\ |
| / \ |
| +---------+ |
| | | |
+---------------------------------+
| Available Letters |
+---------------------------------+
| A B C D E F G H I J K L M |
| N O P G R S T U V W X Y Z |
+---------------------------------+
| Guess The Word: |
+---------------------------------+
| |
+---------------------------------+
Enter A Letter To Guess:
The third image is where we set the 'inputed\letter' and 'scanned_letter' variables. It is just a for loop that sets 'scanned_letter' to the next letter of the word that is chosen. And inputed letter is the letter that the use inputs into the console.
void checkword(){
scannedletter = wordword_check;
for (inputedletter = word[wordcheck]; wordcheck < word.lenght(); wordcheck++){
scannedletter = word[wordcheck];
if (inputedletter == scannedletter){
correctguess();
}
}
}
And this is where I declared the 'blank\word' and 'scanned_letter' variables.
std::string blankword = "";
std::string inputedletter;
std::string words3 = {"chalk", "sheet", "coal"}
std::string word = ""
int wordcheck = 0;
std::string scannedletter = "";
bool wordchosen = false;
And then the error I'm getting is.
error: no viable overloaded operator[] for type 'std::string' (aka 'basicstring<char>')
Any help would be appreciated thanks.
https://redd.it/1h3oam5
@r_cpp
The difficulties of clang and gcc on MacMini M4
I have put in a bug report at pybind11 ( https://github.com/pybind/pybind11/issues/5455 ). I am making two shared objects that can be built and work on Apple Core i7 no problem. I have been able to make the first shared object on MacMini M4 after a lot of fiddling with python. But, I expect for there to be difficulties. What I did not expect is the almost impossibility of consistently invoking homebrew gcc 14.2.0 without extreme force and the resultant ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked shared library product. Ergo: GCC on M4 is giving me NOT an ARM64 .so, but rather an x86_64 .so. What is a poor boy to do?
https://redd.it/1h5zn45
@r_cpp
Latest News From Upcoming C++ Conferences (2024-12-03)
This Reddit post will now be a roundup of any **new** news from upcoming conferences with then the full list now being available at [https://programmingarchive.com/upcoming-conference-news/](https://programmingarchive.com/upcoming-conference-news/)
**C++Online - 25th - 28th February 2025**
* The call for speakers for C++Online has now closed.
**CppCon**
* The CppCon Early Access Program has now been reduced by 25% to $112.50 as some of the videos have started being publically released. For more information, including how to purchase, please visit [https://cppcon.org/early-access/](https://cppcon.org/early-access/)
**ADC**
* ADCx India has been announced and will take place in conjunction with Music Hack Day India from January 17th - 19th 2025. ADCx India is accessible online and in-person and you can find out more at [https://audio.dev/adcx-india-25/](https://audio.dev/adcx-india-25/) and also submit a proposal if you are interested in speaking in-person which closes on Saturday.
https://redd.it/1h5rz0j
@r_cpp
C++ programmer′s guide to undefined behavior: part 10 of 11
https://pvs-studio.com/en/blog/posts/cpp/1193/
https://redd.it/1h5kzkj
@r_cpp
C++ thread-pool with parallel loop interface
https://github.com/hosseinmoein/Leopard
https://redd.it/1h58f9o
@r_cpp
Cpp ressources in 24
It's just me or is it really hard to find ressources about c++? I just spent almost a month making a login and sign up function with sqlite3 and cpp because I can't find as much stuff online as Python, like it's almost if there was no tutorials for cpp, or it could be me that I am just bad
https://redd.it/1h524l1
@r_cpp
Why CPP is the best language to avoid brutal competition.
*\*Disclaimer: All the thoughts given below are my personal understanding and beliefs. They might be wrong, so I leave it to the reader to decide.*
We all are worried about the current market. The layoffs and brutal competition are making everyone anxious, especially students like me who are going to graduate in the coming years.
I speculate that this condition has been forged due to a number of reasons (aside from mindless COVID hirings):
* Easy access to Software Development tutorials.
* The previously held hype regarding the industry.
Both of these have led to a surge of engineers, most of whom are web developers. These developers often consider other programming languages as inferior because they are not used on the web, and they don't even think about their potential uses.
As a result, most new-age developers in the market are Web Devs who primarily know the MERN/MEAN stack, and if they're more sensible, then Java (a good option btw).
All this has led to the unpopularity of C++ language, which I believe is a good thing. This has led to less competition in this field. C++ has a high barrier to entry, as it has comparatively fewer learning resources and is not as easy to learn as other web development-centric languages.
I do believe that it's also hard to land a C++ role. It’s not an easy thing. I would go as far as to say that it's even more difficult to land a role here than other languages because of its intricacies and nature(needing you to be an expert at it). But here you can be sure that you have more aspects in hand during an interview, and the only reason you might not be able to land a job is purely your skill issue.
Well, this was my take on it. I want to remind you that I am a student, and this is what I believe is the market scenario. I am open to discussions and different views.
https://redd.it/1h52zwj
@r_cpp
Legacy Safety: The Wrocław C++ Meeting
https://cor3ntin.github.io/posts/profiles/
https://redd.it/1h4zhvp
@r_cpp
Progress on P1729R0 - Text Parsing?
I am once again participating in Advent of Code (AoC) and have once again run into an issue with my hand rolled input parsing header. Mostly because I never do any file parsing except for AoC and as such am terribly out of practice, but also because I feel like C++ isn't all that great at doing that.
I remember a few years ago there was a paper on bringing scnlib into the standard library, which to me seemed like the input pendant to std::format: A modern and less verbose way of reading and parsing.
Does anyone happen to know what became of it? The scnlib repo seems alive and well.
https://redd.it/1h4r2te
@r_cpp
Anyone here also write in C# or Java? here is my experience.
I'm a newer c++ dev but have more than a decade of C# and Javascript/Typescript under my belt. With my toes dipped in Python and others.
So far, I'm beginning to get very close to my level of productivity in C# for the kind of application I'm writing. I'm working on the next iteration of a concert lighting control system. The older version was made in C#, and suffered from performance issues.
I'm thinking I'm an outlier. To clarify, my level of productivity drops significantly relative to C# whenever I need to interact with any tooling like building, compile times, cmake, adding libraries, ect. However, I have way more of a selection of libraries that don't try to give you a car, and rather just an engine, for the problem I'm solving - which I prefer. The greater level of control has definitely helped my productivity. Maybe its because I enjoy coding more with the level of control I have now.
When it comes to just getting down on my knees and writing code, I find that I'm almost just as productive, especially when it comes to writing critical hot-path code. I did not expect this. Writing "business logic" is only slightly more painful in my opinion too.
To be more specific about critical code. You can totally write performant code in C# and if you are good, maybe you can write something that runs very close or in some rare cases faster than c++. The problem though, is that when you want to write fast C#, you sort of fly with one eye open. Heap allocations are extremely subtle, and happening everywhere. You have to be almost as careful as you do in c++, but instead you are eating from the other end of the icecream cone. Sometimes you start breaking out unsafe declarations, and fixed statements, and then your c# code becomes more verbose than c++. I've seen reddit posts from r/dotnet where benchmarks are posted of c++ vs c# and the C# versions are scarier looking than c++, and they are not using idiomatic C#. Because of this, libraries and UI frameworks that I've used are often resource hogs, and not written to be performance first. This is fine though, C# is still fast, but to squeeze that last 20 percent or so out, you need to step outside daily idiomatic C#. Idiomatic C# is (go crazy with new(), write a lot of closures, iterate over collections many times (linq), assignments, ect)
I will say, for "good-enough-performance" code, it is easier not to fuck up in C#. C++ does require more discipline and thought. Besides memory management, you have to be on your toes about deep copies and assignments, and much more. A lot of higher level programmers are not at all used to the copy by default nature of c++.
C++ has been way less scary than I thought and was told. I think people give it too much shade. To be fair, old c++ vs modern is much scarier.
https://redd.it/1h4nbga
@r_cpp
How to use stack implementation using c++ without exception handling.
https://redd.it/1h4k1ac
@r_cpp
Why the Heck Aren’t We Using std::launder More in C++?
Alright, let’s talk about the most underappreciated function in modern C++: std::launder. Everyone out here is geeking out over std::move, std::optional, and std::vector::emplace_back, but nobody’s giving love to std::launder, the unsung hero of low-level programming. Like, do people even know it exists? Or are we all just blissfully ignoring strict aliasing rules and pretending UB isn’t lurking behind the scenes, waiting to eat our code?
Here’s the thing: std::launder is the ultimate "get out of jail free" card when you’re dealing with weird object lifetimes, placement new, or type-punning. You know, those scenarios where the C++ standard gets all passive-aggressive with phrases like "the behavior is undefined"? Yeah, that’s where std::launder steps in, does a little magic, and makes your code actually legal.
But nooooo, instead of using it, people just sprinkle their code with reinterpret_cast like it’s parmesan cheese on spaghetti and hope for the best. Guess what? That’s not how C++ works. Without std::launder, the compiler is well within its rights to look at your code, laugh, and optimize it straight into the trash bin. You want to break strict aliasing? You want to pretend you’re smarter than the optimizer? Fine, but don’t come crying to me when your program works in debug mode and then mysteriously segfaults in release.
And let’s not forget the placement new crowd. If you’re out here manually constructing objects in pre-allocated memory and not using std::launder, you’re basically playing Russian roulette with UB. Why? Because without it, the compiler doesn’t have to acknowledge that the new object even exists. That pointer you’ve been holding onto? As far as the compiler’s concerned, it’s still pointing to the old, destroyed object. But slap a std::launder on there, and bam, problem solved. The compiler says, "Oh, okay, I’ll actually consider this a valid object now."
But no, people ignore it because they think it’s "too niche" or "too complicated." Meanwhile, they’re writing blog posts about how they "definitely understand" std::enable_if and SFINAE, but can’t be bothered to learn one function that literally saves their code from self-destruction.
Here’s the kicker: std::launder is so underrated that people don’t even realize when they need it. "But my code works fine without it!" Sure, buddy, until the day the optimizer decides to be clever and your program behaves like it’s haunted. And then you’ll be on Stack Overflow asking why your pointer suddenly can’t access its object, and someone will drop the std::launder bomb, and your mind will be blown.
So here’s my plea: Stop ignoring std::launder. Stop pretending UB isn’t your problem. Use it when you’re doing low-level wizardry, and spare the rest of us from having to debug your cursed code when it breaks in ways nobody can predict. It’s there for a reason. Learn it. Use it. Appreciate it. Or don’t—and enjoy your adventures in the wonderful world of undefined behavior. Your choice.
https://redd.it/1h4ckux
@r_cpp
VSCode or CLion for medium to big C++ projects
Hi there. I'm a second year CS student and with some mate we've started the very first medium sized project. As I use Linux the only viable options I see to use as IDE is CLion and VSCode (yes, it's not an IDE) with cmake, clangd, compiler and debugger. As I'm a student CLion is free for now. I've used VSCode for two years now and firstly I didn't see any problems at all.
Then there were some problems in parsing templated classes and a lot of wrongly generated errors, so I moved from standard C++ extension from Microsoft to clangd. It may be because I'm stupid or something but I haven't figured out how to make clangd works properly (parsing is ok, but it doesn't provide any keyword tips as I type), so I use it in concert with MS extension. And for some more time things went fine.
But now, as we work with libraries a lot, there are a great deal of cases when clangd just says that there are so many errors emitted in headers that it just stops. I've became accustomed to working with VSCode, using cmake and some command line scripts for building, running and testing. It's not perfect, but it's enough for me. But I'm not that strong yet as guys who can do C++ in Emacs without linting and code highlighting and some hints.
So I've installed CLion but it looks and feels tremendously different, more like VS. I should constantly use mouse because it uses console instead of terminal and there are all the new workflow for me.
And there is a question - does industry mainly use VS and CLion for real world C++ projects? If so - it's useful to get accustomed to at least one of them, if not - I'm better spend some more time to grind leetcode or preparing for exams.
Thanks in advance for long reading and your help!
https://redd.it/1h4a31d
@r_cpp
Am I still getting better using ChatGPT on projects ?
I use ChatGPT for a lot of my projects , but it feels as if that’s all I use. I was building something last weekend and I understood all the code that was going on and it was somewhat a new topic to me but I only coded a little myself mainly focusing on guiding ChatGPT to build the stuff I couldn’t figure and just fix its code. Will I still get better at programming by doing this or am I shooting my left in the foot ?
https://redd.it/1h479jz
@r_cpp
C++ Show and Tell - December 2024
Use this thread to share anything you've written in C++. This includes:
* a tool you've written
* a game you've been working on
* your first non-trivial C++ program
The rules of this thread are very straight forward:
* The project must involve C++ in some way.
* It must be something you (alone or with others) have done.
* Please share a link, if applicable.
* Please post images, if applicable.
If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.
Last month's thread: https://www.reddit.com/r/cpp/comments/1glnhsf/c_show_and_tell_november_2024/
https://redd.it/1h40wiy
@r_cpp
How is min and max not defined here?
\#ifndef min
\#define min( a, b ) ( (a) <= (b) ? (a) : (b) )
\#endif
\#ifndef max
\#define max( a, b ) ( (a) >= (b) ? (a) : (b) )
\#endif
\#ifndef clamp
\#define clamp( x, a, b ) min( max( (x), (a) ), (b) )
\#endif
https://redd.it/1h3lhw5
@r_cpp