this post was submitted on 22 Jul 2025
430 points (98.2% liked)

Programmer Humor

25620 readers
917 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That's why I love C++

you are viewing a single comment's thread
view the rest of the comments
[–] merc@sh.itjust.works 43 points 2 weeks ago (11 children)

"C++ compilers also warn you..."

Ok, quick question here for people who work in C++ with other people (not personal projects). How many warnings does the code produce when it's compiled?

I've written a little bit of C++ decades ago, and since then I've worked alongside devs who worked on C++ projects. I've never seen a codebase that didn't produce hundreds if not thousands of lines of warnings when compiling.

[–] Zacryon@feddit.org 26 points 2 weeks ago (1 children)

I mostly see warnings when compiling source code of other projects. If you get a warning as a dev, it's your responsibility to deal with it. But also your risk, if you don't. I made it a habit to fix every warning in my own projects. For prototyping I might ignore them temporarily. Some types of warnings are unavoidable sometimes.

If you want to make yourself not ignore warnings, you can compile with -Werror if using GCC/G++ to make the compiler a pedantic asshole that doesn't compile until you fix every fucking warning. Not advisable for drafting code, but definitely if you want to ship it.

[–] Valmond@lemmy.world 2 points 2 weeks ago

Except when you have to cast size_t on int and vice versa (for "small" numbers). I hate that warning.

[–] jkercher@programming.dev 19 points 2 weeks ago (1 children)

You shouldn't have any warnings. They can be totally benign, but when you get used to seeing warnings, you will not see the one that does matter.

[–] merc@sh.itjust.works 6 points 2 weeks ago

I know, that's why it bothered me that it seemed to be "policy" to just ignore them.

[–] Jankatarch@lemmy.world 19 points 2 weeks ago

I put -Werror at the end of my makefile cflags so it actually treats warnings as errors now.

[–] nroth@lemmy.world 13 points 2 weeks ago

0 in our case, but we are pretty strict. Same at the first place I worked too. Big tech companies.

[–] dejected_warp_core@lemmy.world 10 points 2 weeks ago (1 children)

Ideally? Zero. I'm sure some teams require "warnings as errors" as a compiler setting for all work to pass muster.

In reality, there's going to be odd corner-cases where some non-type-safe stuff is needed, which will make your compiler unhappy. I've seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn't matter how good my code is.

There's also a shedload of legacy things going on a lot of the time, like having to just let all warnings through because of the handful of places that will never be warning free. IMO its a way better practice to turn a warning off for a specific line.. Sad thing is, it's newer than C++ itself and is implementation dependent, so it probably doesn't get used as much.

[–] merc@sh.itjust.works 4 points 2 weeks ago (1 children)

I've seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn't matter how good my code is.

Yeah, I've seen that too. The problem is that once the library starts spitting out warnings it's hard to spot your own warnings.

[–] dejected_warp_core@lemmy.world 4 points 2 weeks ago

Yuuup. Makes me wonder if there's a viable "diaper pattern" for this kind of thing. I'm sure someone has solved that, just not with the usual old-school packaging tools (e.g. automake).

[–] Ajen@sh.itjust.works 6 points 2 weeks ago

My team uses the -Werror flag, so our code won't compile if there are any warnings at all.

[–] Croquette@sh.itjust.works 6 points 2 weeks ago (1 children)

A production code should never have any warning left. This is a simple rule that will save a lot of headaches.

[–] phoenixz@lemmy.ca 4 points 2 weeks ago

Neither should your development code, except for the part where you're working on.

[–] vivendi@programming.dev 4 points 2 weeks ago (1 children)

Ignoring warnings is really not a good way to deal with it. If a compiler is bitching about something there is a reason to.

A lot of times the devs are too overworked or a little underloaded in the supply of fucks to give, so they ignore them.

In some really high quality codebases, they turn on "treat warnings as errors" to ensure better code.

[–] merc@sh.itjust.works 2 points 2 weeks ago

I know that should be the philosophy, but is it? In my experience it seems to be normal to ignore warnings.

[–] sunbeam60@lemmy.one 4 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

Depends on the age of the codebase, the age of the compiler and the culture of the team.

I’ve arrived into a team with 1000+ warnings, no const correctness (code had been ported from a C codebase) and nothing but C style casts. Within 6 months, we had it all cleaned up but my least favourite memory from that time was “I’ll just make this const correct; ah, right, and then this; and now I have to do this” etc etc. A right pain.

[–] merc@sh.itjust.works 3 points 2 weeks ago (2 children)

So, did you get it down to 0 warnings and manage to keep it there? Or did it eventually start creeping up again?

[–] shane@feddit.nl 2 points 2 weeks ago

I'm not the person you're asking but surely they just told the compiler to treat warnings as errors after that. No warnings can creep in then!

[–] sunbeam60@lemmy.one 1 points 2 weeks ago

Once we were at zero warnings, we enabled warnings as errors, despite the protestation of the grognards on the team.

[–] jmicz3d@lemmy.sdf.org 3 points 2 weeks ago

I work on one of the larger c++ projects out there (20 to 50 million lines range) and though I don't see the full build logs I've yet to see a component that has a warning.