The gcc compiler detects functions in the C binary search program by default

caipenghui caipenghui_c@163.com
Sun Dec 29 02:56:00 GMT 2019


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;
>> }
>>
>>



More information about the Gcc-bugs mailing list