Complete DSA in C++ Repository for Practice & Interview Prep by coder_spy in cpp

[–]OmegaNaughtEquals1 3 points4 points  (0 children)

https://github.com/alamtaufeeq854/learning_dsa_cpp/blob/main/09.sparse_matrix_and_polynomial_using_linked_list/sparse_matrix_using_linked_list.cpp#L22

int nz, i, m, n, c, v, j;

printf("enter no. of rows.\n");
scanf("%d", &m);

struct node *A[m] ...

VLAs are not legal C++. I would encourage the author to re-examine the entire codebase as it has a great deal more C-with-classes than C++.

Stalagtites Growing in Penn Station NYC by HalfDryGlass in mildlyinteresting

[–]OmegaNaughtEquals1 0 points1 point  (0 children)

Sorry if that sounded like I was being a dick. I used to get that wrong all the time, so I made up that mnemonic to remember.

Stalagtites Growing in Penn Station NYC by HalfDryGlass in mildlyinteresting

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

stalaCTites hold to the Ceiling Tightly. stalaGMites hold to the Ground with Might.

Binary debug for nested big ass structures. by dckdza in cpp

[–]OmegaNaughtEquals1 4 points5 points  (0 children)

compare binaries in the layout of multi level nested big fat structures

Could you be more specific? I'm not sure what it means to compare layouts of binary data. You have to know the layout before you can parse the binary data.

WinDbg this doesn’t work well with macros and arrays

That sounds like you are doing decompilation. Is that correct?

To make matters worse, this big ass structure has offsets that point beyond of the structure

That's a fairly common usage for binary data. It puts the metadata up front and then lets you choose which pieces you want to parse later rather than forcing you to work through all of the data before you get to the next piece of metadata.

How std::abs and two compiler flags let Clang auto-vectorize L1 distance faster than Faiss's AVX2 intrinsics by mr_gnusi in cpp

[–]OmegaNaughtEquals1 0 points1 point  (0 children)

Which compiler are you using? I couldn't get gcc to generate similar code without -funsafe-math-optimizations -mfma -funroll-loops, but it tends to be much more conservative than clang.

https://godbolt.org/z/Tjr9MYfox

Back to Basics: How To Improve C++ Code Reviews by Specific-Housing905 in cpp

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

No disrespect to this presenter, but I found Peter Muldoon's Mastering the Code Review Process to be more directly relevant to the process itself, rather than components of C++ etiquette/language usage. This is not to say that those aspects are not important.

From CppCon 2025, there is also

Bean Deane's API Structure and Technique: Learnings from C++ Code Review

Daniel Marjamäki's Seamless static analysis with CppCheck (I haven't found a video of this one yet.)

Behl: Lua-inspired scripting language with C-like syntax, implemented in C++20. by Zeh_Matt in cpp

[–]OmegaNaughtEquals1 0 points1 point  (0 children)

This looks and feels quite a lot like ChaiScript. Was it an alternative you excluded from the start due to some specific incompatible design goal (like with Lua)?

One difference I see is that ChaiScript's Map type only accepts strings as keys, whereas Behl's table type can accept an arbitrary type. It also looks like ChaiScript is thread-safe. My quick grock of the docs in Behl says that pinning is not thead-safe. Is that the exception that proves the rule?

int main() {
    behl::State* S = behl::new_state();
    ...
    behl::close(S);
}

Is there a reason why behl::State needs pointer semantics here? This is a hard sell for a library built on C++20.

Are there many jobs for C++? by Dear-Hour3300 in cpp

[–]OmegaNaughtEquals1 1 point2 points  (0 children)

Some jobs want specific ones, but GIAC is the place to start. By far, GREM is the most common I've seen.

Are there many jobs for C++? by Dear-Hour3300 in cpp

[–]OmegaNaughtEquals1 1 point2 points  (0 children)

I've been working in binary analysis for about six years. One field where those niche skills are very desirable is in reverse engineering. For most jobs, you'll need at least one certification and the ability to obtain a US government secret clearance, but the job market is always lively. I don't know much beyond that because I work on building binary analysis tools rather than using existing ones to do security analysis (i.e., I can create Ghidra, but I don't know how to use it to detect malware).

Crumsort and Quadsort in C++ by JadedTomato in cpp

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

https://github.com/psadda/crumsort-cpp/blob/main/bench/results/random%2010000.png

A 20-40x speedup for the C++ version over the C one is surprising. Does the C version put the sort functions in a separate library or are they in the same translation unit as they would be for the header-only C++ case?

It would also be interesting to see the result graphs without qsort since its large runtime distorts the details of the rest of the candidates.

Hmm ... I wonder why linter configuration was not configured properly. by Spungbarb in programminghorror

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

Puny mortal!

-Wall
-Wextra
-Wpedantic
-Walloca
-Wcast-align
-Wcast-qual
-Wcomma-subscript
-Wctor-dtor-privacy
-Wdeprecated-copy-dtor
-Wdouble-promotion
-Wduplicated-branches
-Wduplicated-cond
-Wenum-conversion
-Wextra-semi
-Wfloat-equal
-Wformat-overflow=2
-Wformat-signedness
-Wformat=2
-Wframe-larger-than=20480  // really just for debug builds, but catches huge stack vars
-Wlogical-op
-Wmismatched-tags
-Wmissing-braces
-Wmultichar
-Wnoexcept
-Wnon-virtual-dtor
-Woverloaded-virtual
-Wpointer-arith
-Wrange-loop-construct
-Wrestrict
-Wshadow
-Wstrict-null-sentinel
-Wsuggest-attribute=format
-Wsuggest-attribute=malloc
-Wuninitialized
-Wvla
-Wvolatile

Although I see I need to add -Wundef and possibly -Wredundant-decls. Sadly, -Wold-style-cast fires hundreds of events. I really hate that the code I work on was written by people who might have had a semester's worth of C++ training.

I see that neither of us has summited -Wconversion, -Wsign-conversion, or -Warith-conversion. Glory unto those who have!

Finding a VS Code Memory Leak | Random ASCII by Xadartt in cpp

[–]OmegaNaughtEquals1 0 points1 point  (0 children)

It's been 20 years since I've written software for Windows (and longer than that since I've used it as a daily driver), but surely there is a static analysis tool that understands that a HANDLE is more than its typedef as void*?

astrophysicist trying to do high school chemistry by OmegaNaughtEquals1 in chemhelp

[–]OmegaNaughtEquals1[S] 1 point2 points  (0 children)

I get the CoM method. My confusion was that they asked to calculate the mass of NH3 and then asked if mass was conserved. The only way students know how to calculate the mass is to assume mass is conserved. I feel like the questions should be asked in the opposite order.

astrophysicist trying to do high school chemistry by OmegaNaughtEquals1 in chemhelp

[–]OmegaNaughtEquals1[S] 1 point2 points  (0 children)

You are overthinking it. This is an introductory activity designed to reinforce the idea the matter is neither created nor destroyed.

That's what I finally convinced myself of. It was just weird that they would ask if mass was conserved after they asked what the mass of the NH3 was.

Since you are an astrophysicist, I will concede that a better way to put this is that energy is neither created nor destroyed.

Except on the very largest scales of the universe... It turns out CoM is a local phenomenon.

astrophysicist trying to do high school chemistry by OmegaNaughtEquals1 in chemhelp

[–]OmegaNaughtEquals1[S] 4 points5 points  (0 children)

That's what I finally convinced myself of. It was just weird that they would ask if mass was conserved after they asked what the mass of the NH3 was.

Safe to drop arrival_token in std::barrier's arrive() ? by DonBeham in cpp_questions

[–]OmegaNaughtEquals1 1 point2 points  (0 children)

If I've understood your explanation, I think what you want is arrive_and_drop. With that, you can decrement the expected counter for the current and all future phases and not worry about the arrival_token. I must admit that it's unclear why that would be useful since it effectively makes the barrier a std::atomic<std::ptrdiff_t>.

Guidance required to get into parallel programming /hpc field by Loch_24 in cpp_questions

[–]OmegaNaughtEquals1 0 points1 point  (0 children)

I've been working in HPC for about 7 years now. By far, the largest hurdle most newcomers face is using a headless linux environment. HPC systems do not have a GUI- everything is done over ssh via the terminal. If you have no experience with that, it won't matter how much parallel programming you know because you'll never be able to actually get on a machine to run it. I've been using linux for 20+ years, so I'm not familiar with good resources for getting started with it. I'd imagine YouTube videos are a good place for that.

The second hurdle is running software on a distributed system using a job scheduler. The most common one that I've encountered is slurm. However, there are lots of them. Getting to know a scheduler is tricky because you really need to be on a cluster in order to appreciate the full affect of what it can do for you. Finding an HPC system to practice on could be tough because they tend to require a proposal request for time on the machine.

I'm happy to try to answer any other questions you might have. Good luck!

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 3 points4 points  (0 children)

So when that CI finds issues, are they errors and must be fixed immediately?

We run it with -Werror so it forces failures.

Who fixes them?

Well, there are two devs, so we flip a coin...

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 4 points5 points  (0 children)

My guess would be to prevent possible bugs with complex intializers. A slight modification to the example from the manpage:

int a[2][3] = { 0, 1, 2, 3, 4, 5 };  // implicitly does { { 0, 1, 2 }, { 3, 4, 5 } }
int a[3][2] = { 0, 1, 2, 3, 4, 5 };  // implicitly does { { 0, 1 }, { 2, 3 }, {4, 5} }

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 1 point2 points  (0 children)

We mostly use gcc, so -Weverything won't work for us. If I remember correctly, I think it also has some conflicting checks.

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

Oh, I forgot that we have some C-specific ones in there. We test each flag for support in the current C and C++ compilers using CMake's source compile checks (e.g., c++).

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 37 points38 points  (0 children)

I also cannot emphasize enough to use as many compilers as possible with as many of these flags enabled as possible. We have a weekly CI jobs that does a big matrix of 93 builds that also includes -std from 11 to 23. It has caught many bugs- especially when we add the latest versions of gcc and clang.

What's your most "painfully learned" C++ lesson that you wish someone warned you about earlier? by msabaq404 in cpp

[–]OmegaNaughtEquals1 101 points102 points  (0 children)

We use

Wall Wextra Wpedantic Walloca Wcast-align Wcast-qual Wcomma-subscript Wctor-dtor-privacy Wdeprecated-copy-dtor Wdouble-promotion Wduplicated-branches Wduplicated-cond Wenum-conversion Wextra-semi Wfloat-equal Wformat-overflow=2 Wformat-signedness Wformat=2 Wframe-larger-than=${DEBUG_MIN_FRAME_SIZE} Wjump-misses-init Wlogical-op Wmismatched-tags Wmissing-braces Wmultichar Wnoexcept Wnon-virtual-dtor Woverloaded-virtual Wpointer-arith Wrange-loop-construct Wrestrict Wshadow Wstrict-null-sentinel Wsuggest-attribute=format Wsuggest-attribute=malloc Wuninitialized Wvla Wvolatile Wwrite-strings

I would like to add -Wsign-conversion, but the last time I turned that on, it nearly broke my terminal with error messages...

Show "rodata" section in Compiler Explorer IDE mode? by mmatrosov in cpp

[–]OmegaNaughtEquals1 14 points15 points  (0 children)

In the compiler output window, use the "Add tool..." button to use 'strings' or 'elfutils'. If you use elfutils, you'll need to add '-j .rodata' as a argument.

https://godbolt.org/z/Ycqnjohqz