• Lojcs@lemm.ee
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    17 hours ago

    Kind of unrelated, why does c sometimes fail to print if it hits a breakpoint right after a print while debugging? Or if it segfaults right after too iirc

    • huf [he/him]@hexbear.net
      link
      fedilink
      English
      arrow-up
      2
      ·
      59 minutes ago

      does anything flush the buffers after the print, but before the break? otherwise, if the stream you’re printing to is buffered, you’re not necessarily gonna see any output

    • joucker29@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      14 hours ago

      Im pretty sure its because of char 13 (carriage return). This char sets cursor to the start of the line overwriting whatever was printed there (in most terminals). I belive that some error messages use this char and when you print something the char at the begining or end of the error message overwrites your message. A workaround is simply printing a newline after or before your message.

    • targetx@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      16 hours ago

      Without knowing the details of C, I’ve seen this in other languages and it’s usually something with missing a flush or a buffered output mode or something like that.