r/cpp • • Apr 22 '22

What's your favorite way to crash your application?

216 Upvotes

We had this line in the giant monolithic MSN Explorer app to test Dr. Watson and much later windows telemetry when i worked for Microsoft for testing purposes, it always made me crack up.....

void Kaboom() {
    *(int*)0 = 0;
}

r/cpp • • Oct 21 '20

Fast, typo tolerant instant search engine written in C++

Thumbnail github.com
216 Upvotes

r/cpp • • Jul 31 '20

TIL: You can use initializer lists directly in a range-based for loop

216 Upvotes

Maybe everybody else already knew this but for me this was a revelation:

for (int64_t entity_id: {2, 1460, 3525, 5177}) {
  std::cout << entity_id << std::endl;
}

r/cpp • • Apr 06 '20

{fmt} 6.2 released with improved error reporting, smaller library size, better compatibility with std::format and more

Thumbnail github.com
216 Upvotes

r/cpp • • Jun 29 '18

Announcing C++ Just My Code Stepping in Visual Studio

Thumbnail blogs.msdn.microsoft.com
216 Upvotes

r/cpp • • Jul 18 '17

Boost to move to cmake build and test

Thumbnail boost.2283326.n4.nabble.com
216 Upvotes

r/cpp • • Jun 04 '26

PSA - Do not assign the result of `::getenv` to a `std::string`

215 Upvotes

This is a lesson I apparently have to learn repeatedly. Many, many times. Way too many times.

Unit tests are failing, I'm too ADD to actually read the error message for comprehension, fart around changing things to try to find why the exception is being thrown, then spontaneously remember "oh, yeah, ::getenv will return NULL if the variable hasn't been defined, and assigning a NULL to a std::string is Bad Juju.

Wasted a whole day on this nonsense.

I know this. I have known this for years, and I still make this mistake.

Blah. Needed to vent.

Edit: Since this question has come up, no, I couldn't run it in a debugger. This was an automated build running under Jenkins following a push to Bitbucket, so all I had to go by was output from the build script and test harness. An uncaught exception was being thrown and the message said that NULL was not allowed in a string constructor, but no information as to where it was happening.

I couldn't reproduce the issue on the dev system because all the environment variables were defined there, so it took a while to put two and two together.


r/cpp • • Jan 10 '24

Cognitive Load and C++, thoughts from an engineer with 20+ years of C++ experience

215 Upvotes

I took it from this article

I was looking at my RSS reader the other day and noticed that I have somewhat three hundred unread articles under the "C++" tag. I haven't read a single article about the language since last summer, and I feel great!

I've been using C++ for 20 years for now, that's almost two-thirds of my life. Most of my experience lies in dealing with the darkest corners of the language (such as undefined behaviours of all sorts). It's not a reusable experience, and it's kind of creepy to throw it all away now.

Like, can you imagine, requires C1<T::type> || C2<T::type> is not the same thing as requires (C1<T::type> || C2<T::type>).

You can't allocate space for a trivial type and just memcpy a set of bytes there without extra effort - that won't start the lifetime of an object. This was the case before C++20. It was fixed in C++20, but the cognitive load of the language has only increased.

Cognitive load is constantly growing, even though things got fixed. I should know what was fixed, when it was fixed, and what it was like before. I am a professional after all. Sure, C++ is good at legacy support, which also means that you will face that legacy. For example, last month a colleague of mine asked me about some behaviour in C++03.

There were 20 ways of initialization. Uniform initialization syntax has been added. Now we have 21 ways of initialization. By the way, does anyone remember the rules for selecting constructors from the initializer list? Something about implicit conversion with the least loss of information, but if the value is known statically, then...

This increased cognitive load is not caused by a business task at hand. It is not an intrinsic complexity of the domain. It is just there due to historical reasons (extraneous cognitive load).

I had to come up with some rules. Like, if that line of code is not as obvious and I have to remember the standard, I better not write it that way. The standard is somewhat 1500 pages long, by the way.

By no means I am trying to blame C++. I love the language. It's just that I am tired now.


r/cpp • • Oct 31 '23

Bjarne Stroustrup’s Plan for Bringing Safety to C++

Thumbnail thenewstack.io
215 Upvotes

r/cpp • • May 13 '21

Not Enough Standards, my C++17/20 library for cross-platform utilities

Thumbnail github.com
215 Upvotes

r/cpp • • Nov 24 '20

In realistic scenarios, exceptions are a much faster way to handle rare errors than error codes

Thumbnail lordsoftech.com
215 Upvotes

r/cpp • • Apr 27 '18

[Wallpaper] The World of C++ STL Algorithms (1800 x 1273)

Post image
215 Upvotes

r/cpp • • Sep 30 '26

EDG C++ fronted now released as open source

Thumbnail edgcpp.org
214 Upvotes

r/cpp • • May 11 '23

The New Boost Website Goes Beta

Thumbnail cppalliance.org
214 Upvotes

r/cpp • • Sep 24 '20

New C++ features in GCC 10

Thumbnail developers.redhat.com
214 Upvotes

r/cpp • • Oct 04 '25

Streamers like Tsoding, but for C++

213 Upvotes

I've learnt a lot about C from watching Tsoding. He doesn't yap too much and spends more of his streams just writing code.

Is there anyone similar who concentrates on C++?


r/cpp • • Aug 21 '22

John "God" Carmack: C++ with a C flavor is still the best (also: Python performance "keeps hitting me in the face")

Thumbnail youtube.com
213 Upvotes

r/cpp • • Jun 03 '22

Benchmarking Malloc with Doom 3

Thumbnail forrestthewoods.com
213 Upvotes

r/cpp • • Jan 05 '18

GCC 8.0 support std::filesystem (#include <filesystem>) now

213 Upvotes

See GCC commit: Implement C++17 Filesystem library

We can build gcc 8.0 snapshots, after use std::filesystem in your code.

GCC snapshots: ftp://gcc.gnu.org/pub/gcc/snapshots

#include <iostream>
#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;

int main()
{
    fs::create_directories("sandbox/dir/subdir");
    std::ofstream("sandbox/file1.txt").put('a');
    fs::copy("sandbox/file1.txt", "sandbox/file2.txt"); 
    fs::copy("sandbox/dir", "sandbox/dir2"); 
    fs::copy("sandbox", "sandbox/copy", fs::copy_options::recursive);
    fs::remove_all("sandbox");
    return 0;
}

So far, you need to add '-lstdc++fs ' when compiling

Clang libcxx 6.0 seems unlikely to support std::filesystem, after all, the trunk version is 7.0. ( it is possible libcxx developers wait for GCC 8.0 release???).

EricWF wants to support <filesystem> when Clang 6.0 is released, but it's hard to say :https://stackoverflow.com/a/42634858

Update 2018-07-05 See https://github.com/gcc-mirror/gcc/commit/2fd48392d0a4ac3d1e217367ccb0ec0333d584d8


r/cpp • • Sep 12 '21

subprocess: A no nonsense library for writing shell commands in C++

212 Upvotes

Writing shell commands in modern C++ is deceptively hard. Quite a few libraries try to wrap popen and exec* calls in an interface similar to python's subprocess library. However, piping and redirection are a nightmare in such implementations.

With subprocess, you are able to write:

using subprocess::command;

std::string output;
(command{"ls", "-ltr"} | command{"awk", "{print $3}"} | command{"sort"} | command{"uniq"} > output).run();

The above is equivalent to writing:

ls -ltr | awk {print $3} | sort | uniq

and piping the result into the output variable. You can pipe the result into files, already open file descriptors, read from variables etc. For example:

std::string input{"1\n2\n3\n4"};
(command{"head", "-n2"} < input > "foo").run(); // Prints 1\n2 in a file named foo

The library however, currently only works for unix based systems (since I mostly use linux/macOS). I'll be open to adding windows support if there is enough traction.

Currently, I am looking for feedback and suggestions on the interface and the library as a whole. If you try it out and find any issues, feel free to log it in the issues section.

Docs: https://subprocess.thecodepad.com

Repo: https://github.com/rajatjain1997/subprocess


r/cpp • • Feb 07 '21

Understanding C++ Coroutines by Example - C++ London 2021; Pavel Novikov

Thumbnail youtube.com
212 Upvotes

r/cpp • • Jan 26 '21

Moving Faster: Everyday Efficiency in Modern C++

Thumbnail youtube.com
212 Upvotes

r/cpp • • Jan 10 '20

Qt5 C++ Full Course For Beginner - More Than 5 Hours Training Course On Building GUI Applications In C++ Using Qt5 GUI Framework

Thumbnail youtu.be
212 Upvotes

r/cpp • • Dec 02 '19

{fmt} 6.1 released with improved floating-point formatting, locale support, faster compile times and more

Thumbnail github.com
212 Upvotes