Ah've got them Function Pointer blues
- From: "MikeC" <Mike.Best@xxxxxxxxxxxxx>
- Date: Thu, 21 Aug 2008 00:14:10 +0100
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 pointer> is of unknown type - in
function_structure[2] it may be
int func_1(int, int) {....}
in function_structure[5], it may be
void func_2(char **cpt) {....}
etc.
I would like to initialise the array directly, like
struct FS function_structure[] = {{ ....}, {....}, ...., {....}};
.... 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$btconnect*com
$ = @
* = dot
.
- Follow-Ups:
- Re: Ah've got them Function Pointer blues
- From: MikeC
- Re: Ah've got them Function Pointer blues
- Prev by Date: Re: binary file
- Next by Date: Re: Storgae durations
- Previous by thread: Reading char* word by word
- Next by thread: Re: Ah've got them Function Pointer blues
- Index(es):
Relevant Pages
|