Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Sunday March 16, 2003
07:53 AM

Odd use of sign

[ #11053 ]
Dear All,

From the RTF spec:

\abshN -- N is the height of the frame in twips. A positive number indicates the minimum height of the frame, and a negative number indicates the exact height of the frame. A value of zero indicates that the height of the frame adjusts to the contents of the frame. This is the default for frames where no height is given.

have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • What happens when that one positive value rolls over into another negative value? :) Anarchy? Chaos?
  • by ziggy (25) on 2003.03.16 11:00 (#17969) Journal
    Have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?
    I'm pretty sure I have, but I don't remember where. It may have been another MSAPI, which would confirm this example as an instance of MSThinking 1.0.

    This seems like the kind of trickery a newbie C hacker would use in the days when they're being too clever by half. Especially something that would have been common in the early 1990s when C was starting to catch on big time in the microcomputing world.

    Thankfully, those days don't last very long (or there would be all sorts of other trickery hanging on the boolean nature of the sign bit.) Unfortunately, sometimes those tricks make it into public APIs.

  • Not quite the same but time range arguments to find are absolute if there is no sign, or ranges if there is a sign (+ and - are interpreted as > and <).

    So, -atime 5 means accessed 5 days ago, -atime -5 means accessed less than 5 days ago, and -atime +5 means accessed more than 5 days ago. Most of the time, you want a signed version. (How often do you want to find files used exactly 37 days ago, and be sure it wasn't 36 or 38?)

  • have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?

    I can give you two examples in Perl.

    1. (s)sprintf templates, "%10s" vs. "%-10s"... where one means align to the left, the other, align to the right.
    2. substr, where negative numbers for a numerical parameter mean from the end. In particular, check out the third parameter, LENGTH, which is not a length but the end offset (from the end) if it's negative.

      $s = j