Share Pastebin
Guest
Public paste!

godrik

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 1.08 KB | Hits: 10 | Expires: Never
Copy text to clipboard
  1. erik@powell:/tmp$ cat test.c
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int main ()
  7. {
  8.   double (*fnct)(double);
  9.  
  10.   double i;
  11.   char buf[19];
  12.   scanf ("%p %lf %s", &fnct, &i, buf);
  13.   printf ("%lf %d\n",fnct(i), strlen(buf));
  14.   return 0;
  15. }
  16. erik@powell:/tmp$ gcc -lgsl -lm  -lgslcblas test.c -o test -g
  17. erik@powell:/tmp$ gdb test
  18. GNU gdb 6.8-debian
  19. Copyright (C) 2008 Free Software Foundation, Inc.
  20. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  21. This is free software: you are free to change and redistribute it.
  22. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  23. and "show warranty" for details.
  24. This GDB was configured as "x86_64-linux-gnu"...
  25. (gdb) b main
  26. Breakpoint 1 at 0x4006a5: file test.c, line 11.
  27. (gdb) r
  28. Starting program: /tmp/test
  29.  
  30. Breakpoint 1, main () at test.c:11
  31. 11        scanf ("%p %lf %s", &fnct, &i, buf);
  32. (gdb) p sqrt
  33. $1 = {<text variable, no debug info>} 0x7fa6075f3d50 <sqrt>
  34. (gdb) p sqrt(4)
  35. $2 = 0
  36. (gdb) set variable fnct=sqrt
  37. (gdb) set variable i=4
  38. (gdb) p fnct(i)
  39. $3 = 2