--- raja <[email protected]> wrote:
> hi,
> I am writing a function that takes the return
> value of the another
> function and gives the status of the function.
> if
> error("functionName",arguments)
> here the function with Name "functionName " is to be
> executed with the
> corresponding argunents.But by knowing the function
> name how can i get
> the address if that function and how can i execute
> the function with the
> arguments.
>
Dude, this is not the right forum for these types of
questions. You need to look at some good general
texts. I don't know if you can get a copy of Steven's
or other general Unix programming text, but that's
what would help you the most. Anyway, here's an
example for you. The C compiler in general treats a
function name as a type of pointer, similar to an
array base pointer in that you cannot modify it, but
you can de-reference it.
/* Crude demo program for calling a function
* by indirect means and supplying arguments.
*
* Yes, it's GPL. :-)
*/
#include <stdio.h>
int foo(char *message)
{
int error = 0;
if (message)
printf("%s\n", message);
else
error = 1;
return error;
}
int call_a_function(int (*func)(char *), char *arg)
{
return (*func)(arg);
}
int main(int argc, char *argv[])
{
int (*func)(char *);
char *arg;
if (argc == 2) {
func = foo;
arg = argv[1];
return call_a_function(func, arg);
} else {
return 1;
}
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
|
|