308
average c++ dev (programming.dev)

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++

top 50 comments
sorted by: hot top controversial new old
[-] LovableSidekick@lemmy.world 4 points 1 hour ago

As it should be. Airbags should go off when you crash, not when you drive near the edge of a cliff.

[-] merc@sh.itjust.works 6 points 1 hour ago

"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.

[-] jkercher@programming.dev 6 points 1 hour ago

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 1 points 50 minutes ago

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

[-] Zacryon@feddit.org 4 points 30 minutes ago

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.

[-] witx@lemmy.sdf.org 2 points 47 minutes ago

None. We treat warnings as compiler errors with a compiler flag

[-] sunbeam60@lemmy.one 1 points 1 hour ago* (last edited 1 hour ago)

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 1 points 49 minutes ago

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

[-] vivendi@programming.dev 1 points 1 hour ago

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 1 points 50 minutes ago

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

[-] Gobbel2000@programming.dev 11 points 5 hours ago

I'm all for having the ability to do these shenanigans in principle, but prefer if they are guarded in an unsafe block.

[-] BigDanishGuy@sh.itjust.works 18 points 8 hours ago

But it will let you do it if you really want to.

Now, I've seen this a couple of times in this post. The idea that the compiler will let you do anything is so bizarre to me. It's not a matter of being allowed by the software to do anything. The software will do what you goddamn tell it to do, or it gets replaced.

WE'RE the humans, we're not asking some silicon diodes for permission. What the actual fuck?!? We created the fucking thing to do our bidding, and now we're all oh pwueez mr computer sir, may I have another ADC EAX, R13? FUCK THAT! Either the computer performs like the tool it is, or it goes the way of broken hammers and lawnmowers!

[-] AnyOldName3@lemmy.world 5 points 2 hours ago

Soldiers are supposed to question potentially-illegal orders and refuse to execute them if their commanding officer can't give a good reason why they're justified. Being in charge doesn't mean you're infallible, and there are plenty of mistakes programmers make that the compiler can detect.

[-] BigDanishGuy@sh.itjust.works 3 points 1 hour ago

I get the analogy, but I don't think that it's valid. Soldiers are, much to the chagrin of their commanders, sentient beings, and should question potentially illegal orders.

Where the analogy doesn't hold is, besides my computer not being sentient, what I'm prevented from doing isn't against the law of man.

I'm not claiming to be infallible. After all to err is human, and I'm indeed very human. But throw me a warning when I do something that goes against best practices, that's fine. Whether I deal with it is something for me to decide. But stopping me from doing what I'm trying to do, because it's potentially problematic? GTFO with that kinda BS.

[-] Throskie@midwest.social 1 points 1 hour ago

This comment makes me want to reformat every fucking i use and bend it to -my- will like some sort of technomancer

[-] daniskarma@lemmy.dbzer0.com 8 points 6 hours ago

I will botton for my rust compiler, I'm not going to argue with it.

[-] WhyJiffie@sh.itjust.works 4 points 5 hours ago

when life gives you restrictive compilers, don't request permission from them! make life take the compilers back! Get mad! I don’t want your damn restrictive compilers, what the hell am I supposed to do with these? Demand to see life’s manager! Make life rue the day it thought it could give BigDanishGuy restrictive compilers! Do you know who I am? I’m the man who’s gonna burn your house down! With the compilers! I’m gonna get my engineers to invent a combustible compiler that burns your house down!

[-] BuboScandiacus@mander.xyz 13 points 8 hours ago

Ok gramps now take your meds and off you go to the retirement home

[-] BigDanishGuy@sh.itjust.works 4 points 1 hour ago

Stupid cloud, who's laughing now?

[-] Treczoks@lemmy.world 15 points 9 hours ago

Structs with union members that allow the same place in memory to be accessed either word-wise, byte-wise, or even bit-wise are a god-sent for everyone who needs to access IO-spaces, and I'm happy my C-compiler lets me do it.

[-] psycho_driver@lemmy.world 13 points 9 hours ago

I don't know which is worse. Using C++ like lazy C, or using C++ like it was designed to be used.

[-] UnfortunateShort@lemmy.world 19 points 10 hours ago* (last edited 7 hours ago)

I used to love C++ until I learned Rust. Now I think it is obnoxious, because even if you write modern C++, without raw pointers, casting and the like, you will be constantly questioning whether you do stuff right. The spec is just way too complicated at this point and it can only get worse, unless they choose to break backwards compatibility and throw out the pre C++11 bullshit

[-] Zacryon@feddit.org 1 points 27 minutes ago

I suppose it's a matter of experience and practise. The more you wotk with it the better you get. As usual with all things one can learn.

[-] mobotsar@sh.itjust.works 12 points 6 hours ago

Depending on what I'm doing, sometimes rust will annoy me just as much. Often I'm doing something I know is definitely right, but I have to go through so much ceremony to get it to work in rust. The most commonly annoying example I can think of is trying to mutually borrow two distinct fields of a struct at the same time. You can't do it. It's the worst.

[-] dragonlobster@programming.dev 6 points 8 hours ago

No need to cast as any types at all just work with bits directly /s

[-] magic_lobster_party@fedia.io 38 points 13 hours ago

There are no medals waiting for you by writing overly clever code. Trust me, I’ve tried. There’s no pride. Only pain.

[-] Zacryon@feddit.org 1 points 20 minutes ago

But I must o p t i m i z e! ó_ò

Yes, let's spend two hours on figuring out optimal values of preallocating a vector for your specific use-case. It's worth the couple of microseconds saved! Kleinvieh macht auch Mist.

[-] merc@sh.itjust.works 3 points 1 hour ago

Not only that, but everyone who sees that code later is going to waste so much time trying to understand it. That includes future you.

[-] Zacryon@feddit.org 1 points 26 minutes ago

That what comments and documentation are for.

[-] Chrobin@discuss.tchncs.de 20 points 11 hours ago

It really depends on your field. I'm doing my master's thesis in HPC, and there, clever programming is really worth it.

[-] magic_lobster_party@fedia.io 12 points 9 hours ago

Well as long you know what you’re doing and weigh the risks with the benefits you’re probably ok.

In my experience in the industry, there’s little benefit in pretending you’re John Carmack writing fast inverse square root. Understanding what you wrote 6 months ago outweighs most else.

[-] MonkderVierte@lemmy.zip 5 points 10 hours ago

Clever as in elegantly and readable or clever as in a hack that abuses a bug/feature and you need to understand the intricacies to understand half of it?

[-] Chrobin@discuss.tchncs.de 9 points 9 hours ago

Honestly, also the latter. If you are using hundreds of thousands of cores for over 100h, every single second counts.

[-] Contramuffin@lemmy.world 71 points 18 hours ago

What do you mean I'm not supposed to add 0x5f3759df to a float casted as a long, bitshifted right by 1?

load more comments (4 replies)
load more comments
view more: next ›
this post was submitted on 22 Jul 2025
308 points (98.7% liked)

Programmer Humor

25180 readers
1674 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