in reply to Re^7: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

NULL is a special pointer in C, and an exceptional value in in SQL and VB.
NUL is ASCII character 0.

I believe you are refereing to NUL.

Replies are listed 'Best First'.
Re^9: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
by mr_mischief (Monsignor) on Sep 13, 2007 at 17:52 UTC
    More to the point, since we've been working with byte values instead of characters for some time now (the very purpose of use bytes), isn't chr(0) indeed the same as '\0'? NUL is a null (notice the lowercase -- just meaning 0-valued and not anything special in jargon terms -- this is Webster's definition 4b or definition 6) byte. chr(0) is a zero-valued byte. NUL is chr(0). Right?UpdateI was thinking for some reason the last couple of days that single-character escapes worked in single quotes, and that only variable interpolation didn't. I don't know why, because I know better than that. I'll blame extreme tiredness, as that's likely the cause.

    I'm not an optimization guru or anything, but isn't working with the data at a lower level a common optimization technique? IIRC, it's a big part of why the core C language uses chars that are basically small integers, and that strings are represented by arrays of chars. It's easy for the compiler, and it's very efficient. It's certainly not because it makes programming string-heavy projects easier.

    I would really like to see the benchmark run that is showing my code failing the "same output" test, if such data exists. Update: This concerns me about the test, then, because my broken version doesn't seem to have ever killed the test.

      I was replying to specifically to something dragonchild said. I hadn't read the thread that led up to his post until now.

      "\0" produces a single character string consisting of character zero (NUL).
      chr(0) produces a single character string consisting of character zero (NUL).
      The problem is that you used '\0'.
      '\0' produces a two character string consisting of a backslash (\) and a zero (0).

      >perl -le "$s=qq{\0}; $,=q{, }; print length($s), qq{[$s]}, $s eq chr( +0) ?1:0" 1, [ ], 1 >perl -le "$s=q{\0}; $,=q{, }; print length($s), qq{[$s]}, $s eq chr(0 +) ?1:0" 2, [\0], 0

      dragonchild should have recommended "\0" instead of the slower chr(0), but he was right to say '\0' is wrong.

      And finally, I can accept that "null byte" (lowercase "null") can mean "a byte with value zero". When I corrected dragonchild, he had said NULL.

        Ah, that's correct. '\0' is wrong. "\0" it is then. I forgot for a moment that q() and '' don't interpolate even single character escapes.