← Back to context

Comment by rswail

16 days ago

So what exactly is the NUL/0 in the code below other than a sentinel value?

    while (*d++ = *s++)
        ;

I am not sure what this is in response to. Can you explain which point of mine you are responding to?

  • > If the hardware had instructions for sentinel values, things would be easier (Like how DOS calls used '$' termination for strings) and safer.

    A zero is a sentinel value and is catered to by all ISAs.

    Why would using a "$" be any easier/safer than a NUL?

    • > A zero is a sentinel value and is catered to by all ISAs.

      > Why would using a "$" be any easier/safer than a NUL?

      I didn't say it had to be '$'; I specifically said that the sentinel would be loaded into a register. In that case it could be anything, including zero (for the snippet you posted), or INT_MAX if the code iterated across an array of integers, etc.

      By having rep/mov variants that use sentinels, a lot of the HLL problems go away - Java, C#, Python, etc would all look very different today if the ISAs from the 80s included sentinal variant of memory instructions.

      3 replies →