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

  • Gobbel2000@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    3 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
    link
    fedilink
    arrow-up
    17
    arrow-down
    4
    ·
    6 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!

    • WhyJiffie@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 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!

    • Owl@mander.xyz
      link
      fedilink
      arrow-up
      15
      arrow-down
      2
      ·
      5 hours ago

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

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    12
    ·
    6 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.

  • UnfortunateShort@lemmy.world
    link
    fedilink
    English
    arrow-up
    18
    ·
    edit-2
    4 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

    • mobotsar@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      7
      ·
      4 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.

  • magic_lobster_party@fedia.io
    link
    fedilink
    arrow-up
    34
    arrow-down
    1
    ·
    11 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.

    • Chrobin@discuss.tchncs.de
      link
      fedilink
      arrow-up
      18
      arrow-down
      1
      ·
      9 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
        link
        fedilink
        arrow-up
        10
        ·
        7 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
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        7 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
          link
          fedilink
          arrow-up
          6
          ·
          7 hours ago

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

  • panda_abyss@lemmy.ca
    link
    fedilink
    arrow-up
    72
    arrow-down
    1
    ·
    16 hours ago

    I actually do like that C/C++ let you do this stuff.

    Sometimes it’s nice to acknowledge that I’m writing software for a computer and it’s all just bytes. Sometimes I don’t really want to wrestle with the ivory tower of abstract type theory mixed with vague compiler errors, I just want to allocate a block of memory and apply a minimal set rules on top.

    • Kairos@lemmy.today
      link
      fedilink
      arrow-up
      7
      arrow-down
      28
      ·
      14 hours ago

      People just think that applying arbitrary rules somehow makes software magically more secure, like with rust, as if the compiler won’t just “let you” do the exact same fucking thing if you type the unsafe keyword

      • witx@lemmy.sdf.org
        link
        fedilink
        arrow-up
        14
        arrow-down
        2
        ·
        edit-2
        8 hours ago

        I want you to stop what you’re doing, pause and read your comment again slowly. What you’re arguing is analogous to: “People just think that strapping a cloth to them in the car will make driving more secure. As if someone can’t just not use the seatbelt and still die in a car crash from that.”

        It’s not arbitarious rules, it’s math and computer science. Wth are you some kind of science denier? Have they reached the computer science realm, like “Big O is out to get you?”

        These rules do make Rust safer than c++ not in term of business logic but in terms of memory handling. I’ve been doing c++ for a looooooong time and once in a while there are times where we lose days if not weeks tracking down a race condition or memory bug where we could have been tracking down business logic bugs, improving code quality and coverage, adding features, etc

        • Kairos@lemmy.today
          link
          fedilink
          arrow-up
          4
          arrow-down
          1
          ·
          8 hours ago

          That’s not what I meant. I understand that rust forces things to be more secure. It’s not not like there’s some guarantee that rust is automatically safe, and C++ is automatically unsafe.

          • witx@lemmy.sdf.org
            link
            fedilink
            arrow-up
            9
            arrow-down
            2
            ·
            edit-2
            6 hours ago

            Safe in what regards? You’re being cagey on purpose. In terms of memory there is a guarantee that Rust is automatically safer than c++, period. Im business Logic? Sure you’re right

      • BatmanAoD@programming.dev
        link
        fedilink
        arrow-up
        17
        ·
        11 hours ago

        It’s neither arbitrary nor magic; it’s math. And unsafe doesn’t disable the type system, it just lets you dereference raw pointers.

      • Speiser0@feddit.org
        link
        fedilink
        arrow-up
        8
        ·
        13 hours ago

        You don’t even need unsafe, you can just take user input and execute it in a shell and rust will let you do it. Totally insecure!

        • Ignotum@lemmy.world
          link
          fedilink
          arrow-up
          9
          arrow-down
          1
          ·
          9 hours ago

          Rust isn’t memory safe because you can invoke another program that isn’t memory safe?

          • Speiser0@feddit.org
            link
            fedilink
            arrow-up
            3
            ·
            41 minutes ago

            My comment is sarcastic, obviously. The argument Kairos gave is similar to this. You can still introduce vulnerabilities. The issue is normally that you introduce them accidentally. Rust gives you safety, but does not put your code into a sandbox. It looked to me like they weren’t aware of this difference.

      • panda_abyss@lemmy.ca
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        13 hours ago

        I don’t know rust, but for example in Swift the type system can make things way more difficult.

        Before they added macros if you wanted to write ORM code on a SQL database it was brutal, and if you need to go into raw buffers it’s generally easier to just write C/objc code and a bridging header. The type system can make it harder to reason about performance too because you lose some visibility in what actually gets compiled.

        The Swift type system has improved, but I’ve spent a lot of time fighting with it. I just try to avoid generics and type erasure now.

        I’ve had similar experiences with Java and Scala.

        That’s what I mean about it being nice to drop out of setting up some type hierarchy and interfaces and just working with a raw buffers or function pointers.

    • mindbleach@sh.itjust.works
      link
      fedilink
      arrow-up
      23
      ·
      12 hours ago

      C is dangerous like your uncle who drinks and smokes. Y’wanna make a weedwhacker-powered skateboard? Bitchin’! Nail that fucker on there good, she’ll be right. Get a bunch of C folks together and they’ll avoid all the stupid easy ways to kill somebody, in service to building something properly dangerous. They’ll raise the stakes from “accident” to “disaster.” Whether or not it works, it’s gonna blow people away.

      C++ is dangerous like a quiet librarian who knows exactly which forbidden tomes you’re looking for. He and his… associates… will gladly share all the dark magic you know how to ask about. They’ll assure you that the power cosmic would never, without sufficient warning, pull someone inside-out. They don’t question why a loving god would allow the powers you crave. They will show you which runes to carve, and then, they will hand you the knife.

  • wer2@lemmy.zip
    link
    fedilink
    arrow-up
    25
    arrow-down
    1
    ·
    15 hours ago

    My issue is C++ will “let me do it”, and by that I mean “you didn’t cast here (which is UB), so I will optimize out a null check later, and then segfault in a random location”

  • Pennomi@lemmy.world
    link
    fedilink
    English
    arrow-up
    30
    ·
    17 hours ago

    C++ is kinky that way. You can consent to all manner of depraved programming patterns. Great for use in personal life, but maybe not appropriate for the office.