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

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


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?

/ * 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