9.10 binary Find gcc makefile gdb debug

Source: Internet
Author: User

iterative and recursive implementations of binary lookups:
  
 
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int find1(int *a, int low , int high , int key)//迭代二分查找
  4. {
  5. int mid = 0;
  6. while (low <= high)
  7. {
  8. mid = (low+high)/2;
  9. if (a[mid] == key)
  10. return mid;
  11. else if (a[mid] < key)
  12. low = mid + 1;
  13. else
  14. high = mid -1;
  15. }
  16. return -1;
  17. }
  18. int find2(int *a, int low , int high , int key) //递归二分查找
  19. {
  20. if (low > high)
  21. return -1;
  22. int mid = (low+high)/2;
  23. if (a[mid] == key)
  24. return mid;
  25. else if (a[mid] < key)
  26. find1(a,mid+1,high,key);
  27. else
  28. find1(a,low,mid-1,key);
  29. }
  30. int main()
  31. { /code>
  32. int array Span class= "pun" >[ 13 ] = { 2 6 8 12 32 64 67 78 98 104 120 134 140
  33. int key = find2(array,0,12,140);
  34. printf("%d\n",array[key]);
  35. return 0;
  36. }


gcc Common options


How does gcc know the file type? Determine file types by file extension



Makefile rules follow the general form
target:dependency [dependency[...] Dependency is the meaning of dependenceCommandCommand[...]The first character of each command must be the TAB key, not the space key, or make will error and stop.



a slightly more complex makefile, which reads as follows:
start:hello.ogcc-o Hello hello.o
hello.o:gcc-o hello.o-c hello.c
The hello.o behind target start stands for the command dependent on the target with HELLO.O. so make first executes the command under the target of HELLO.O.


use variables in makefile:
cc=gccsrcs=hello.cobjs=$ (SRCS:.C=.O) Exec=hello
START:HELLO.O $ (CC)-O $ (EXEC) $ (OBJS) @echo '---------------OK---------------'
HELLO.O: $ (CC)-O $ (OBJS)-C $ (SRCS)
Clean:rm-f hello.o
add Variable cc,SRCs, Objs, EXEC,Each reference variable is expanded to a variable value in the place of the CC. objs=$ (SRCS:.C=.O), which means to replace. C in the SRCS variable with. O.



Makefile Pattern Rules
. Suffixes:. C. o indicates that any x.c file is associated with X.O. C.O: Indicates that make defines a rule, and any X.O files are compiled from X.C make defines some useful pre-defined variables
examples of automatic variables and pattern rules are used in makefile and multiple source files can be compiled
. Suffixes:.c. OCC=GCCsrcs=hello.c\PUB.C
objs=$ (SRCS:.C=.O)Exec=hello
start:$ (OBJS)$ (CC)-O $ (EXEC) $ (OBJS)@echo '---------------OK---------------'
. C.O:$ (CC)-o [email protected]-C $<
Clean :rm-f $ (OBJS)


GDB debugging must be added to the-G option:

GDB program name [Corefile] The corefile is optional, but it enhances GDB's ability to debug. Linux does not generate Corefile by default, so it needs to be added in the user profile
vi. ProfileUlimit-c Unlimited.. Profile

gdb App Core


From for notes (Wiz)

9.10 binary Find gcc makefile gdb debug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.