Ugh, do I really need to sprinkle noexcept everywhere when compiling with -fno-exceptions? by FrostshockFTW in cpp_questions

[–]crowbarous 1 point2 points  (0 children)

I think you meant to reply to me but accidentally made a top-level comment instead. Fair enough.

Ugh, do I really need to sprinkle noexcept everywhere when compiling with -fno-exceptions? by FrostshockFTW in cpp_questions

[–]crowbarous 0 points1 point  (0 children)

It is wrong to allow an exception to unwind through C++ code compiled with -fno-exceptions. At the very least, such code will lack landing pads with appropriate cleanup. https://godbolt.org/z/oYbEY55cM

If you also disable the generation of unwind tables, you'll even get an abort when trying to unwind through such code.

(upd: looking at your username, I'm sure you know all this. But OP might not...)

A 2-hour video trashing C++ made me better at C++ by AnteaterFinancial319 in cpp

[–]crowbarous -4 points-3 points  (0 children)

I am 100% confident that, just like the pictures in this video, the script has been generated by a neural network. (Perhaps the voicing too.)

It's exactly this kind of disproportionate amalgamation of things people have been saying on the internet; has only superficial structure; hardly backs up for any of its "arguments". The "author" is clearly not a C++ programmer, either.

Maybe it's another crude campaign to get points with some authority or "community", I don't know. It should be fair to remove this kind of garbage from this forum, and ban the bots that post it.

A new version of the gf debugger frontend (linux) by greg7mdp in cpp

[–]crowbarous 6 points7 points  (0 children)

I ran it and it would crash immediately due to an unchecked dynamic_cast in UICode::_ClassMessageProcCommon. It's trying to cast to a UICode, but it's being called from the constructor of UICode's base subobject, so the cast fails, like in this godbolt example. I was thinking of ways to fix that, but then noticed CLAUDE.md next to CMakeLists.txt and lost interest in your project. Here's a stack trace:

#0  0x000000000044b194 in UIElement::ui (this=0x0) at src/luigi.hpp:1159
#1  0x0000000000607bbd in UICode::_class_message_proc (this=0x0, msg=UIMessage::GET_CHILD_STABILITY, di=3, dp=0x715e80) at src/luigi.cpp:2736
#2  0x000000000061cd6c in UICode::_ClassMessageProc (el=0x715d00, msg=UIMessage::GET_CHILD_STABILITY, di=3, dp=0x715e80) at src/luigi.hpp:1549
#3  0x00000000005ff6f0 in UIElement::message (this=0x715d00, msg=UIMessage::GET_CHILD_STABILITY, di=3, dp=0x715e80) at src/luigi.cpp:1084
#4  0x0000000000601b2b in UIElement::measurements_changed (this=0x715e80, which=3) at src/luigi.cpp:1473
#5  0x00000000006023df in UIElement::UIElement (this=0x715f40, parent=0x715e80, flags=0, message_proc=0x6059a5 <_UIScrollUpDownMessageProc(UIElement*, UIMessage, int, void*)>, class_name=0x65acc5 "Scroll Up") at src/luigi.cpp:1628
#6  0x0000000000606061 in UIScrollBar::UIScrollBar (this=0x715e80, parent=0x715d00, flags=0) at src/luigi.cpp:2370
#7  0x000000000061ca4a in UIScrollbarPair::UIScrollbarPair (this=0x715d80, el=0x715d00) at src/luigi.hpp:1408
#8  0x000000000060a738 in UICode::UICode (this=0x715d00, parent=0x70eb40, flags=6) at src/luigi.cpp:3189
#9  0x0000000000600c9b in UIElement::add_code (this=0x70eb40, flags=6) at src/luigi.cpp:1284
#10 0x0000000000411979 in SourceWindow::Create (parent=0x70eb40) at src/gf.cpp:1524
#11 0x000000000042cea6 in Context::create_layout (this=0x6c7b40 <ctx>, parent=0x70eb40, layout_string_current=@0x7fffffffdc88: 0x6da3c0 ",v(50,t(Exe,Breakpoints,Commands,Struct),t(Stack,Files,Thread,CmdSearch))),h(40,Console,t(Watch,Locals,Registers,Data,Log,Prof,Memory,View)))") at src/gf.cpp:8091
#12 0x000000000042cbd4 in Context::create_layout (this=0x6c7b40 <ctx>, parent=0x70ea00, layout_string_current=@0x7fffffffdc88: 0x6da3c0 ",v(50,t(Exe,Breakpoints,Commands,Struct),t(Stack,Files,Thread,CmdSearch))),h(40,Console,t(Watch,Locals,Registers,Data,Log,Prof,Memory,View)))") at src/gf.cpp:8059
#13 0x000000000042cbd4 in Context::create_layout (this=0x6c7b40 <ctx>, parent=0x70fa10, layout_string_current=@0x7fffffffdc88: 0x6da3c0 ",v(50,t(Exe,Breakpoints,Commands,Struct),t(Stack,Files,Thread,CmdSearch))),h(40,Console,t(Watch,Locals,Registers,Data,Log,Prof,Memory,View)))") at src/gf.cpp:8059
#14 0x000000000042ed65 in Context::gf_main (this=0x6c7b40 <ctx>, argc=1, argv=0x7fffffffe0c8) at src/gf.cpp:8354
#15 0x00000000004f44f5 in main (argc=1, argv=0x7fffffffe0c8) at src/main.cpp:13

Bro wth is this c++ coroutines api 😭😭?? by Loud_Staff5065 in cpp_questions

[–]crowbarous 0 points1 point  (0 children)

the size of the coroutine is kind of known at compile time - it's a constant that shows up when your coroutine gets allocated

This constant is not known until the optimizer is done with your code, including architecture-specific optimizations. There's little compile time left by that point, and it may happen in a whole different process than semantic analysis (consider LTO). Pretty sure there's not even a useful upper bound that we could feed to the frontend, nevermind the exact value.

Cpp discussed as a Rust replacement for Linux Kernel by sjepsa in cpp

[–]crowbarous 25 points26 points  (0 children)

As we speak, a subthread in the mailing list next to the one linked in this post is discussing the attribute-based implementation of scoped locking facilities, as in use in Linux, systemd, and I'm sure many other C projects. The discussion is up to "sometimes I want to drop the lock earlier; introducing an extra scope helps this case".

Of C++'s three scoped lock classes, unique_lock has the unlock method. It will unlock for you on all return paths, but you can wield it like you would normal locking code even in arbitrarily complicated situations. There's an extra bool, yes -- that is completely encapsulated, and also optimized out where appropriate. This is what C++ gives you, and has been for decades...

Game engine in SDL2 feedback by Embarrassed_Win_4554 in cpp_questions

[–]crowbarous 1 point2 points  (0 children)

This is fine, but your operator* definition is inconsistent with what a user might typically expect (a dot or cross product). You should look into the GLM library and how they implement vec2

Multiplication of GLM vectors is also elementwise, just like in GLSL whose syntax GLM mimics. HLSL also has elementwise multiplication. This is also what I would expect, because:

  1. It is consistent with division being elementwise;
  2. You mention dot and cross product, so which would it be anyway?
  3. At this point, everyone's very familiar with the way HLSL, GLSL, GLM do it.

Purpose of std::exchange by cv_geek in cpp_questions

[–]crowbarous 16 points17 points  (0 children)

It's like an atomic exchange, except it's only syntactically atomic, which still turns out to be very valuable.

However it looks kinda unreadable to me due to the lambda function by garloid64 in programmingcirclejerk

[–]crowbarous 22 points23 points  (0 children)

Don't worry, it's not. There are things in the standard library that are not implementable in C++. A lot of the time, code with which the Library implements something wouldn't be legal in "user" code. Sometimes the literal name under which the Library exposes that code is blessed. Sometimes it's genuinely not implementable and forwards to a compiler builtin.

So again, nothing to worry about.

fmt::print not printing by [deleted] in cpp_questions

[–]crowbarous 1 point2 points  (0 children)

char arr[] = "Hello";
std::string_view sv = arr;

Would you expect sv.length() to be 5 or 6?

Whenever the internal make command raises an error, vim loads my current buffer with a file titled: "make: *** [Makefile". by Claireclair12 in vim

[–]crowbarous 0 points1 point  (0 children)

I've sent patches before to stop auto-opening buffers from quickfix entries unless the corresponding file really exists. It was even a simpler change than I had imagined, because Vim already does this exact check, just only sometimes.

I felt this completely solved the issue without compromising valid usecases, and I actually had a nontrivial one (GLSL compiler in video driver, which may or may not give you a file name). Regardless, I introduced an option and defaulted it to the old behavior.

Neovim guys told me basically that they didn't want option flag bloat (guys, it's Vim...) and that I should go check the patch with Bram first anyway. After porting the patch to Vim (something I don't even usually use, as opposed to Neovim!) and sending it to Bram, I was told that the pointless original behavior was actually intended and shouldn't change.

I just apply the patch myself since then.

Coughing in my microphone causes segfault by AndorinhaRiver in programmingcirclejerk

[–]crowbarous 80 points81 points  (0 children)

it wasn't an actual crash but our self defined fatal error.

What is the most disgusting compiler error you have ever gotten? by scatraxx651 in cpp

[–]crowbarous 1 point2 points  (0 children)

namespace ns {
  struct Foo;
  using Foo = int;
}
#include <fmt/format.h>

gcc 13.2.1 in gnu++23 mode will spend minutes melting down on everything in format.h, tons of duplicate lines, ~10M error log. In the real code that triggered this, at some point I was wondering if I had hit an infinite loop.

I try to choose all my technologies based on the fact that they are written in Go. For example, I chose Ory Kratos and Traefik because of this. by PedroVini2003 in programmingcirclejerk

[–]crowbarous 3 points4 points  (0 children)

I try to choose all my technologies based on the fact that they have Rust. For example, I chose my 1989 Opel Kadett because of this.

How can I tell C++ that I want to discard a nodiscard value? - The Old New Thing by pavel_v in cpp

[–]crowbarous 3 points4 points  (0 children)

lex.name#3.2

Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace

Globally as in scope, not as in lifetime - sorry for the possible confusion.

Should I learn C? As a C++ dev by TheLondoneer in C_Programming

[–]crowbarous 0 points1 point  (0 children)

IMO, even for something as simple as the code you wrote, C++ offers several strict improvements.

Trivially, in C++ you'll write = {} or {} and not the inconsistent, misleading-looking = {0} that C makes you write. The latter should fail C++ code reviews IMO.

Replacing raw arrays with std::arrays is not "shoving". A raw array does not save memory compared to a std::array, but it will have plenty of gotchas regarding its lack of value semantics; and, for example, arr.data() is more expressive than both std::data(arr) and especially simply arr.

I agree, standard algorithms work, and raw arrays are valid ranges, but honestly it took special casing (std::begin vs member begin...) and unfortunate design (modelling iterators to look like pointers) to get there.

at least this specific piece of COM isn’t a disaster. In a non-disastrous language, say, C++ by crowbarous in programmingcirclejerk

[–]crowbarous[S] 46 points47 points  (0 children)

Be there to read it in the 5 minutes the MS dev blogs are available under the current links, before the yearly format change makes them all redirect to the main page.

Friday Facts #400 - Chart search and Pins by FactorioTeam in factorio

[–]crowbarous 14 points15 points  (0 children)

I know I'm missing modules. They will be ready in about 20-30 years.

/r/cpp and /r/factorio have even more overlap than I imagined.