r/cpp_questions • • 14h ago

OPEN Why are exceptions so "backstabby"?

14 Upvotes

Simply put, I often find myself being told that exceptions "are not that costly" and that "the compiler puts it on cold sections anyways".

As a forenote, I'm the kind of person who always does `-fno-rtti -fno-exceptions` as I value code size usage (I develop small embedded shit and such, which does lead me to decorate functions with alignas and other thingies). Sometimes I also drop using the libc/libc++ and do syscalls raw because I can't stand the overhead (malloc/operator new is a great general purpouse allocator, but it doesn't suit my specific performance needs for example), so I take the hit from doing a syscall for a big mmap and then manually allocate memory by using fixed upper bounds.

(Ok also because glibc malloc sucks, but that is another topic)

Now with that noted, I have one pique in life: Why should I even use exceptions?

I often find myself removing exceptions of whatever codebase I happen to contribute to. Which does lead to people telling me that "you shouldn't do that".

The reason they often cite is either:

- It's not that important in the grand scheme of things (Valid, but so is every 'death by a thousand cuts')

- It makes code less clear (I'd argue otherwise)

- It's standard/idiomatic (Yeah and so is std::auto_ptr)

I really want to know WHY should I even use exceptions. I feel like they're a waste of language grammar I'm forbidden for touching, for it would bring me great despair.

As a cited case; recently I was working on optimizing a JSON parsing loop (oh scary). Obviously the final solution was not using JSON and just doing raw text with the |0x202020 casecmp trick.

But after collecting the values on a vector (I'd rather prefer a VLA to avoid indirection btw) I saw that the specialization of the vector for the non trivial class did in fact make a bunch of garbage for a case that I would have not hit otherwise.

https://godbolt.org/z/MPb9xnYqx

Like this is dumb, I'm not developing code for an airplane, if the thing runs out of memory it's just gonna crash anyways.

And no, noexcept also sucks because it just wraps shit around {} with std::terminate(), which is dumb (atleast on MSVC, but whatever).


r/cpp_questions • • 11h ago

OPEN Great C++ Software Engineering techniques

12 Upvotes

Currently starting up a new project and I really want to emphasize very sophisticated uses and practices that make it beyond just a toy project and a real software engineering project. I'm using Alpaca for live market feed so I'm learning about socket programming but I wanna ask, what are some very very useful techniques to know that actually prep for C++ software jobs? Stuff like CI/CD, Yaml, and other toolchains that make hiring managers look and take notice


r/cpp_questions • • 21h ago

OPEN I began coding with C++, should I continue learning it or should I drop it and start something else?

4 Upvotes

I have always wanted to learn coding and make games, but I didn't know what to do and how to start. About 4 years ago, I saw Sololearn's ad on Youtube (I'm not advertising them). Desparate to learn, I installed it. First, it asked me a few questions regarding why I want to learn coding, what I'm going to use it for (web designing, game development, ...), etc. After answering them, I got suggested learning C++, so I did. I finished the introduction course and learned about half of the intermediate course (if I remember correctly, the last thing I learned was separate files for classes).

Recently, I found out via social media that C++ is the worst language to learn as your first language. I am pretty comfortable with the syntax, but I do sometimes forget complex things like pointers, constructors and deconstructors, etc, because I don't have the time to code often. I have made a lot of small projects, and I'm currently working on a terminal version of Minesweeper that outputs the game board in colored text and is played via inputting the X and Y coordinates of the tile that you want to open or flag (I don't know how to make buttons, or programs with separate windows in general.)

I wanted to know if I should continue learning this language or should I drop it and learn something else, like Python?

Also, I have recently started working with Git, and I find it pretty complicated and hard to use. It would be nice if someone told me whether I should continue learning and using it or if it is too early and I should finish learning the language first.

(P.S.: Many apologies for my imperfect English; I'm not so good at writing and speaking, as it isn't my native language.)


r/cpp_questions • • 14h ago

OPEN Debugging certificate trust mismatches between Windows and OpenSSL in C++ apps

1 Upvotes

I maintain a C++ app on Windows that does TLS with OpenSSL, and I keep running into the same headache: the same server cert gets accepted by Windows (CryptoAPI/SChannel) but rejected by OpenSSL, or the other way around. Sometimes CryptoAPI builds a valid chain, sometimes OpenSSL can't find a trust anchor even though the cert is clearly in the Windows store. The result flips depending on the store, the CA bundle, and verification flags

For those who've dealt with this from C++

  • How do you actually investigate the difference? Do you dump chains via CryptoAPI, run openssl s_client/verify, write throwaway C++ that calls both APIs and compares, or some mix?
  • Is it usually quick to pin down the exact cause, or does it turn into hours of manual poking?
  • Has anything existing actually made this straightforward for you, or is it still custom glue code?

I'm especially interested in how people maintaining C++ Windows apps handle this in practice what your debugging flow looks like when Windows and OpenSSL disagree on the same cert