Mail Archives: djgpp/1997/08/25/06:32:49
Jeff Weeks wrote:
>
> I'd like to have a function in a struct that I've created. I realise I
> can't just stick a functions in there, so I used a pointer to a
> function. Here's what my struct looks like:
>
> typedef struct {
> VesaInfo card; // information about the video card
> VesaModeInfo mode; // information about the current mode
> int bytes_per_line; // the number of bytes per scanline
> int size; // the size in bytes of the whole screen
> char *address; // the address of actual video memory
> void (*blit)(char *); // a routine to copy a virtual screen to
> memory
> } Driver;
>
> And then I define an instance and set blit to something:
>
> Driver driver;
> driver.blit = lfb_blit;
>
> But when I try to call the actual function, it crashes. I know the
> lfb_blit() function is not at fault (I've tested it separately), so the
> problem is in calling the function from the struct. I do it as follows:
>
> char *virt = (char *)malloc(640*480*2);
> driver.blit(virt);
>
> Can C not do this? Is there no way to call a function from a struct?
> If there is a way (perferable a portable way!) could you please tell me.
>
> If it's not possible, then I'll just write an assembly language
> proceedure to load in the address of blit and jump to it, but I'd perfer
> to be able to do it simply with C code.
This should work ok. I use it myself in a parser where I defined for
each keyword a function that processes the parameters. Are you sure that
your function lfb_blit() works correct? Also you might check the models
(depending on your system). Which memory model do you use?
--
Bye,
Gerhard
- Raw text -