From: "YUBS" Newsgroups: comp.os.msdos.djgpp Subject: help: void pointers Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Message-ID: <8UQq3.6777$K%6.145927@news1.rdc2.on.home.com> Date: Sat, 07 Aug 1999 07:04:36 GMT NNTP-Posting-Host: 24.65.39.101 X-Complaints-To: abuse AT home DOT net X-Trace: news1.rdc2.on.home.com 934009476 24.65.39.101 (Sat, 07 Aug 1999 00:04:36 PDT) NNTP-Posting-Date: Sat, 07 Aug 1999 00:04:36 PDT Organization: @Home Network Canada To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi, I'm having some trouble using void pointers. I'm writing a function that will allocate enough memory for any of my types by using a void pointer as a parameter in the function. I.e. void pcx_init (void *image, char type) So say I have the following type: typdef struct pcx_image_typ { char *buffer; int width, height; } pcx_image, *pcx_image_ptr I want to be able to pass a pointer to a variable of type pcx_image to pcx_init and have it allocate width*height memory for buffer. The problem I'm getting is that DJGPP keeps complaining that I'm "dereferencing "void *" pointer" and that "request for memeber "buffer" in something not a structure or a union". here's my exact code: void pcx_init(void *image, char type) { switch (type) { case 's': { if (!(((pcx_image_ptr)(image->buffer)) = (char * )malloc (image->width* image->height))) } } } I left out the other case since I figured I should isolate the problem and typing it out here would only confuse things. Now, I had to manually copy this so I may have made a typo, but I just wanted to give you the idea of what I'm trying to do. Basically, buffer is going to store a pcx file. I read in the size of the pcx file, store it in width and height, and then call pcx_init to allocate the memory for the buffer. Thing is, I have other types that I'd like to use the same function to allocate memory for, and using void pointers seemed (at the time:-) to be a good idea. Obviously there are numerous ways around this, but I'd like to figure out how to use void pointers anyway, so I may aswell use this scenario as a learning tool. Thanks for any help you can give and if you need me to clarify my explaination (its a little difficult to explain) don't hesitate to ask. Thanks again. -Josh de Bever