A
Andrej Prsa
Hi!
I'm trying to create a small scientific script language; my idea was to
create a struct with the corresponding global variable like this:
typedef struct commands
{
int recno;
int *argc;
char **name;
int *(*func)();
} commands;
commands command;
Then I thought I could create a function that would add commands to this
global variable:
int add_command (char *name, int argc, int func() )
{
/* recno has been set to 0 and all pointers in command set to NULL */
/* elsewhere in the program. */
int i = command.recno++;
command.name = realloc (command.name, i * sizeof (*char));
command.argc = realloc (command.argc, i * sizeof (*int));
command.func = realloc (command.func, i * sizeof (*int));
command.name = strdup (name);
command.argc = argc;
command.func = func;
return 0;
}
You guys can probably see from miles away that I don't know how to assign
a pointer-to-function value to command.func; the most logical thing for me
would be to use something like:
command.(*func)() = ...
but it doesn't work. So please help, how do I do this?
Thanks,
Andrej
I'm trying to create a small scientific script language; my idea was to
create a struct with the corresponding global variable like this:
typedef struct commands
{
int recno;
int *argc;
char **name;
int *(*func)();
} commands;
commands command;
Then I thought I could create a function that would add commands to this
global variable:
int add_command (char *name, int argc, int func() )
{
/* recno has been set to 0 and all pointers in command set to NULL */
/* elsewhere in the program. */
int i = command.recno++;
command.name = realloc (command.name, i * sizeof (*char));
command.argc = realloc (command.argc, i * sizeof (*int));
command.func = realloc (command.func, i * sizeof (*int));
command.name = strdup (name);
command.argc = argc;
command.func = func;
return 0;
}
You guys can probably see from miles away that I don't know how to assign
a pointer-to-function value to command.func; the most logical thing for me
would be to use something like:
command.(*func)() = ...
but it doesn't work. So please help, how do I do this?
Thanks,
Andrej