Re: Ah've got them Function Pointer blues




"August Karlstrom" <fusionfile@xxxxxxxxx> wrote in message
news:g8jtk7$me6$1@xxxxxxxxxxx
MikeC wrote:
[...]
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.

How come the functions have different signature and what do you want to
achieve? Please, tell us a bit more about the underlying problem.


August

Well, I would have done that in the first place, but that's to do with
architecture, not with C, and this is a C group, and flames burn me. In my
original post, I asked:

"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)"

However, as you ask ...

I haven't finished specifying the program yet - I keep having bigger and
better ideas - but I want to write a text macro engine. It will interpret
commands from a (text) command file, executing them on an input (read only)
file, and producing an output file. The commands will be, for example

copy off // don't copy anythying from the input file to the output file
find_forward "a text string"
move_left 6 // characters
copy on // this causes any character scanned by the cursor to be copied to
the output file
loop 6 // times
{ <more commands>
}
etc....

.... you get the idea.
I wanted to run through the command (program) file and compile it into a
forth-like stack (yes, I'm a dinosaur), with each stack element being a
structure, which contains, among other things, a pointer to the function
that will execute the command. The commands do different things, so they
have different signatures, hence my question.

Among all the ways of solving this problem (the architecture problem), I'm
sure people who have spent a life in preofeesional programming will know of
much better methods, and probably be able to pull in other
packages/libraries that would do a lot of the work - but I don't know about
those. I usually write programs from scratch, and write everything.

Last night, I wrote char *stristr(char *str) because it isn't in the
library - though I'm sure it's somewhere (though I wouldn't know where to
look). I'm rather pleased with it! :-)

Regards,

MikeC



.



Relevant Pages

  • Re: Ahve got them Function Pointer blues
    ... and producing an output file. ... The commands will be, for example ... forth-like stack, with each stack element being a ... structure, which contains, among other things, a pointer to the function ...
    (comp.lang.c)
  • Re: [opensuse] Strange desktop setup
    ... to get the desktop to work in a manner I expect it to. ... pointer to the top edge of the screen, the taskbar slides down past the ... bottom edge of the screen and on moving the mouse pointer to the bottom ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: GUNDOG-L Digest - 22 Jul 2005 to 26 Jul 2005 (#2005-113)
    ... You should not have to teach a Pointer ... Pointing is an instinct, not a trained command. ... steps you mention below are teaching the dog to WHOA, ... Repetitive commands given too early and often, ...
    (rec.hunting.dogs)
  • Re: C++/Tk
    ... It would be good to provide some method to access objects through ... I know this would require static types for widget objects). ... What about using function objects instead of pointer ... I got a feeling that for some commands are not required. ...
    (comp.lang.tcl)
  • Mixed Sync/Async communications pattern
    ... looking for a pointer ... Some commands do not require a response from B, and some do, but I ... Async events from B can in turn cause one or more commands from A to ...
    (comp.lang.tcl)