Skip to content

Wrong comparison function in tests for ft_list_sort #5

@JonathanDUFOUR

Description

@JonathanDUFOUR

In the subject of libasm, it is said that the ft_list_sort function must be «like the one in the piscine», so it refers to the subject of the C12, in which it is said that the «Function pointed by cmp will be used as follows:

(*cmp)(list_ptr->data, list_other_ptr->data);

cmp could be for instance ft_strcmp.»

This last sentence makes us understand that the comparison function shall return:

  • a negative int when the first operand is lower than the second one
  • a positive int when the first operand is greater than the second one
  • zero as an int when the two operands are equal

That being said, the current comparison function in the ft_list_sort tests is:

int lower(void *d1, void *d2) { return ((long long)d1 > (long long)d2); }

Which returns either 1 (a positive int) when the first operand is lower than the second one, or 0 otherwise. Therefore, it doesn't meet the requirement of the subject, and should be replaced by something like:

int lower(void *d0, void *d1) { return (int)((__UINTPTR_TYPE__)d0 - (__UINTPTR_TYPE__)d1); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions