Skip to content

strcmp falsely claims it returns a 0, 1 or -1 #3629

Closed
@ash-m

Description

@ash-m

The docs for strcmp say:

Return Values

Returns -1 if string1 is less than string2; 1 if string1 is greater than string2, and 0 if they are equal.

Changelog

Version Description
8.2.0 This function now returns -1 or 1, where it previously returned a negative or positive integer.

Problems:

I believe the intended logic here is:

  • Attempt to calculate the spread between to strings (unpredictable for large spreads)
  • If the strings match except for trailing characters, return the difference in characters

Whatever the logic, it seems like it does not return very predicable results other than being contrasted to 0. Here are some interesting return values: https://3v4l.org/FN86s

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDocumentation contains incorrect information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions