Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. "Fun bug of the month, mesa edition, episode may"

"Fun bug of the month, mesa edition, episode may"

Scheduled Pinned Locked Moved Uncategorized
25 Posts 11 Posters 33 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • karolherbst@chaos.socialK karolherbst@chaos.social

    "Fun bug of the month, mesa edition, episode may"

    so if you do "uint64_t some_var = 1 << 31;" in C you get "0xffffffff80000000" as the value, because that's super obvious and not confusing at all.

    It's pretty funny getting reminded how non-intuitive and broken C is from time to time.

    L This user is from outside of this forum
    L This user is from outside of this forum
    lalufu@mastodon.social
    wrote last edited by
    #21

    @karolherbst I recently read https://www.os2museum.com/wp/bitfield-pitfalls/ which is a similar pitfall?

    1 Reply Last reply
    0
    • karolherbst@chaos.socialK karolherbst@chaos.social

      @pavel @trilader the actual right solution would be to fix the language 😛

      pavel@social.kernel.orgP This user is from outside of this forum
      pavel@social.kernel.orgP This user is from outside of this forum
      pavel@social.kernel.org
      wrote last edited by
      #22
      @karolherbst @trilader Yeah, travelling to 1972 and changing the language would be best :-).
      1 Reply Last reply
      0
      • karolherbst@chaos.socialK karolherbst@chaos.social

        "Fun bug of the month, mesa edition, episode may"

        so if you do "uint64_t some_var = 1 << 31;" in C you get "0xffffffff80000000" as the value, because that's super obvious and not confusing at all.

        It's pretty funny getting reminded how non-intuitive and broken C is from time to time.

        lkundrak@metalhead.clubL This user is from outside of this forum
        lkundrak@metalhead.clubL This user is from outside of this forum
        lkundrak@metalhead.club
        wrote last edited by
        #23

        @karolherbst taking off my "understands sign extension" badge

        wore it with pride, but the pride was misplaced

        1 Reply Last reply
        0
        • trilader@chaos.socialT trilader@chaos.social

          @karolherbst For my understanding: That's default int promotion + sign extend on 64 bit extension? Would 1L << 31L fix this or is there other pitfalls with that?

          lkundrak@metalhead.clubL This user is from outside of this forum
          lkundrak@metalhead.clubL This user is from outside of this forum
          lkundrak@metalhead.club
          wrote last edited by
          #24

          @trilader @karolherbst 1L << alone would do the trick on real world 64-bit machines, but i think compiler is still fully allowed to do the wrong thing. msvc perhaps still has 32-bit longs on 64-bit platforms?

          i think you need to make sure it's unsigned so that sign extension has no chance of occurring, so my money is on 1U << 31?

          1 Reply Last reply
          0
          • karolherbst@chaos.socialK karolherbst@chaos.social

            "Fun bug of the month, mesa edition, episode may"

            so if you do "uint64_t some_var = 1 << 31;" in C you get "0xffffffff80000000" as the value, because that's super obvious and not confusing at all.

            It's pretty funny getting reminded how non-intuitive and broken C is from time to time.

            eniko@mastodon.gamedev.placeE This user is from outside of this forum
            eniko@mastodon.gamedev.placeE This user is from outside of this forum
            eniko@mastodon.gamedev.place
            wrote last edited by
            #25

            @karolherbst ohhh, footgun i didn't know about yet!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups