--
Does anyone know anything about functions that return pointers to functions?
Suppose I want a function that takes an integer argument and returns a
pointer to a function that takes a string argument. I discovered on my own,
after about thirty minutes of trial and error, that I could use a prototype
like the one below:
double (*foo (int a)) (char *c);
where foo is the function that returns a pointer to the string-valued
function, where the referenced function returns a double. The caller would
be as follows:
foo (integer_argument) (string_argument);
I wrote some code to test something like this. I got it working just fine
on a UNIX box and an MS-DOS box. This program has no particular use, it
just demonstrates what I'm talking about. What I am asking is this: does
anyone know whether or not this standard ANSI C?
----------------------------------------------------------- cut here --------
#include <stdio.h>
/* You can put prototypes here if you want to. */
double four (char *c) {
printf ("integer argument is four; string is \"%s\"\n",c);
return 4.0;
}
double two (char *c) {
printf ("integer argument is two; string is \"%s\"\n",c);
return 2.0;
}
double not_two_or_four (char *c) {
printf ("integer argument is not two or four; string is \"%s\"\n",c);
return 0.0;
}
/*
* In this example, foo takes an integer argument and returns a
* pointer to a string-valued function. The referenced string-valued
* function returns a double.
*/
double (*foo (int a)) (char *c)
{
if (a==4)
return four;
else if (a==2)
return two;
else
return not_two_or_four;
}
void main (void)
{
int a;
char str[30];
double (*fp)(char *c);
double z;
while ( scanf("%d %s",&a,str) == 2 ) /* read integer argument and
string argument */
{
fp = foo(a); /* pointer to int-valued function */
(*fp)(str); /* execute that function */
z = foo(a)(str); /* this demonstrates the caller and also
uses the return value of the function
returned by foo. */
printf ("Return value is: %20g\n",z);
}
}
----------------------------------------------------------- cut here --------
--
#!/bin/ksh
RANDOM}%10+2));until [ $c -eq 0 ];do s=$o$s;c=$((${c}-1));done;echo $h|sed "s/\
\(.\)/"$s"/g"|sed "s/^\(.*\)$/"$s"/g"|sed "s/\(.\)"`echo $s|sed "s/"'\\'$o"$//\
g"`"/"$o"/g"|sed "s/^\(.*\)"`echo $s|sed "s/"'\\'$o"$//g"`"$/"$o"/g"