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