← Back to context

Comment by yellowapple

1 year ago

That would imply that such debuggers are storing line numbers as not just 16-bit numbers (which is probably sensible, considering that source files longer than that are uncommon), but as signed 16-bit numbers. I can't fathom a situation where line numbers would ever be negative.

It's not that uncommon of a convention to strictly use signed numbers unless doing bit manipulation, eg the Google C++ Style Guide.

  • Notably, unsigned integers also have defined behavior for overflow. This means compilers can do less optimization on unsigned integers. For example, they can't assume that. x + 1 > x for unsigned ints, but are free to assume that for standard ints.

    That is just another reason to stick with signed ints unless there is a very specific behavior you rely on.

    • > For example, they can't assume that. x + 1 > x for unsigned ints, but are free to assume that for standard ints.

      No they ain't:

          julia> x = typemax(Int16)
          32767
          
          julia> x + Int16(1) > x
          false
      

      Integers are integers, and can roll over regardless of whether or not they're signed. Avoiding rollover is not a reason to stick with signed integers; indeed, rollover is a very good reason to avoid using signed integers unless you're specifically prepared to handle unexpectedly-negative values.

      2 replies →

Maybe somewhere some line offset is stored as i16? (I don't understand why anyway but..)

The __LINE__ macro defaults to "int". That then gets handed to the debugger.

  • The __LINE__ macro, like all other macros, is expanded during the preprocessing of the source code and is not handed to the debugger in any way.

    • Yes... And debuggers that implement line numbers, generally work by taking that information as part of the preprocessing stage. And the #line and __LINE__ macro/directive were implemented _for debuggers_ when originally created. They were made to be handed over to the debugger.

      If you simply compile and run, the debugger won't have __LINE__, no. But it also won't have line numbers, at all. So you might have missed a bit of context to this discussion - how are line numbers implemented in a debugger that does so, without access to the source?

      1 reply →