Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong comparison function in tests for ft_list_sort #5

Open
JonathanDUFOUR opened this issue Sep 24, 2024 · 0 comments
Open

Wrong comparison function in tests for ft_list_sort #5

JonathanDUFOUR opened this issue Sep 24, 2024 · 0 comments

Comments

@JonathanDUFOUR
Copy link

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); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant