Folks,
I've been playing with C programs for 25 years (not professionally -
self-taught), and although I've used function pointers before, I've never
got my head around them enough to be able to think my way through what I
want to do now. I don't know why - I'm fine with most other aspects of the
language, but my brain goes numb when I'm reading about function pointers!
I would like to have an array of structures, something like
struct FS
{ <function pointer>;
<some other variables>;
};
My problem is that the <function pointeris of unknown type - in
function_struct ure[2] it may be
int func_1(int, int) {....}
in function_struct ure[5], it may be
void func_2(char **cpt) {....}
etc.
I would like to initialise the array directly, like
struct FS function_struct ure[] = {{ ....}, {....}, ...., {....}};
.... but I'm really shaky on what to put in those braces. I have been
playing with it, but so far unsuccessfully.
Is it possible? How do I declare the pointer in the structure, and how do I
assign a pointer value to it? And when I call it, how do I pass arguments
from the program? Could somebody give me a very simple example?
This isn't a homework thing, by the way - I write mostly little programs
that get used at work by colleagues. It improves my street-cred
(geek-cred? - well, no - I've just blown that notion!).
Incidentally, this may not be the best way to design the program, so I'd
like to ask about that too.
Can anybody suggest a newsgroup? (program architecture isn't really C)
Thanks,
MikeC
--
Mental decryption required to bamboozle spam robots:
mijewen$btconne ct*com
$ = @
* = dot
I've been playing with C programs for 25 years (not professionally -
self-taught), and although I've used function pointers before, I've never
got my head around them enough to be able to think my way through what I
want to do now. I don't know why - I'm fine with most other aspects of the
language, but my brain goes numb when I'm reading about function pointers!
I would like to have an array of structures, something like
struct FS
{ <function pointer>;
<some other variables>;
};
My problem is that the <function pointeris of unknown type - in
function_struct ure[2] it may be
int func_1(int, int) {....}
in function_struct ure[5], it may be
void func_2(char **cpt) {....}
etc.
I would like to initialise the array directly, like
struct FS function_struct ure[] = {{ ....}, {....}, ...., {....}};
.... but I'm really shaky on what to put in those braces. I have been
playing with it, but so far unsuccessfully.
Is it possible? How do I declare the pointer in the structure, and how do I
assign a pointer value to it? And when I call it, how do I pass arguments
from the program? Could somebody give me a very simple example?
This isn't a homework thing, by the way - I write mostly little programs
that get used at work by colleagues. It improves my street-cred
(geek-cred? - well, no - I've just blown that notion!).
Incidentally, this may not be the best way to design the program, so I'd
like to ask about that too.
Can anybody suggest a newsgroup? (program architecture isn't really C)
Thanks,
MikeC
--
Mental decryption required to bamboozle spam robots:
mijewen$btconne ct*com
$ = @
* = dot
Comment