Oh my god, this is a low-level mistake, not funny 8-0......
caipenghui
å¨ 2019/12/29 10:50, Andrew Pinski åé:
> On Sat, Dec 28, 2019 at 6:31 PM caipenghui <caipenghui_c@163.com> wrote:
>> hello everyone,
>>
>> I found that gcc version 9.2.1 20191008,
>>
>> i to compiles a binary search algorithm program that I write that only
>> checks the function prototype,
>>
>> but does not check the name after the definition?
>>
> bsearch is a standard C function.
> https://pubs.opengroup.org/onlinepubs/009695399/functions/bsearch.html
> http://www.cplusplus.com/reference/cstdlib/bsearch/
>
> Thanks,
> Andrew Pinski
>
>> / * binary bearch * /
>> #include <stdio.h>
>> int bsearch(int x, int a[], int n);
>> int main(void)
>> {
>> int a[] = {
>> 0, 555,
>> 3, 4, 5,
>> 6,
>> };
>> printf("%d\n", bsearch(0, a, sizeof a / sizeof a[0]));
>> return 0;
>> }
>>
>>
>> int abaaaaasjkjjjjjjjjjjjjjkjjjjjjjjjjjjjjjjjjjjjjjjjjjjerch(int x, int
>> a[], int n)
>> {
>> int low;
>> int hig;
>> int mid;
>>
>> low = 0;
>> hig = n - 1;
>> while (low <= hig) {
>> mid = (low + hig) / 2;
>> if (x < *(a + mid))
>> hig = mid - 1;
>> else if (x > *(a + mid))
>> low = mid + 1;
>> else
>> return mid;
>> }
>> return -1;
>> }
>>
>>