Mail Archives: djgpp/1997/08/26/14:25:56
From: | Jeff Weeks <pweeks AT execulink DOT com>
|
Newsgroups: | comp.os.msdos.djgpp,comp.lang.c
|
Subject: | Functions in struct's... possible? How?
|
Date: | Thu, 21 Aug 1997 20:16:28 -0400
|
Organization: | Code X Software
|
Lines: | 45
|
Message-ID: | <33FCDA5C.2353659F@execulink.com>
|
NNTP-Posting-Host: | ppp8.io.execulink.com
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
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.
Any help would be appreciated,
Jeff
PS: If possible, please respond via email.
--------------------------------------------
- Code X Software -
Programming to a Higher Power
email: mailto:pweeks AT execulink DOT com
web: http://www.execulink.com/~pweeks/
--------------------------------------------
- Raw text -