• @xthexder
    link
    fedilink
    28 months ago

    y <= MAX_INT will never be false, since the loop will overflow and wrap around to MIN_INT

    (You can escape code with `backticks`, and regular markdown rules)

    • @[email protected]
      link
      fedilink
      48 months ago

      It will not “overflow”. Signed integer overflow is undefined behavior. The compiler could remove the whole loop or do anything else imaginable (or not).

        • @[email protected]
          link
          fedilink
          18 months ago

          Languages with dynamic typing and implicit large-integer types, such as Python and Ruby, generally just convert to that large-integer type.

          I figured Java would probably define the behavior in the JVM, but based on a quick web search it sounds like it probably doesn’t by default, but does provide library methods to add or subtract safely.

          Rust guarantees a panic by default, but provides library methods for wrapping, saturating, and unchecked (i.e. unsafely opting back in to undefined behavior).

    • @[email protected]
      link
      fedilink
      English
      1
      edit-2
      8 months ago

      Oh good call! What I was trying to do is more complex than I was thinking.

      Hmmmmm.

      int f = TRUE;
      for (int y = MIN_INT; f || y - 1 < y; y++) {
        f = FALSE;
        if (y == x + 1) {
          x = y;
        }
      }
      

      (I should just test my code to make sure it works, but I haven’t. Heh.)

      Also, Lemmy escaped your angle bracket too. Back ticks don’t seem to do the trick.

      Block: <
      

      Inline: <

      Or were you suggesting back ticks for some other purpose? (I did use back ticks in my first post in this thread.)

      • @xthexder
        link
        fedilink
        28 months ago

        The backticks worked in the preview, and showed up correctly to start, but there must be a bug in the lemmy ui, since now it’s double-escaped. No idea /shrug