![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2007
Posts: 3
Rep Power: 0
![]() |
warning: assignment from incompatible pointer type warning in a function poiter
hello there,
I am writing a C program in which I need a function pointer to be assigned. The code is as follows typedef struct nsmail_inputstream {
void *rock;
int (*read) (void *rock,
char *buf, unsigned size);
void (*rewind) (void *rock);
void (*close) (void *rock);
} nsmail_inputstream_t;
int Test_read(void *rock,char *buf, unsigned size)
{
if(fgets(buf,size,(FILE *)rock) == NULL)
return -1;
return strlen(buf);
}
nsmail_inputstream_t l_inputStream;
l_inputStream.read = Test_read;This end up with the following warnings and I can't figure out why please help me, warning: assignment from incompatible pointer type Thanks in advace. --jakh Last edited by big_k105; Aug 16th, 2007 at 2:52 PM. Reason: Changed <code> to [code] |
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
Seems to work for me
![]() #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct nsmail_inputstream {
void *rock;
int (*read)( void *rock, char *buf, unsigned size );
void (*rewind)( void *rock );
void (*close)( void *rock );
} nsmail_inputstream_t;
int Test_read( void *rock, char *buf, unsigned size ) {
if ( fgets( buf, size, (FILE *)rock ) == NULL )
return -1;
return strlen( buf );
}
int main( void ) {
nsmail_inputstream_t inputStream;
inputStream.read = Test_read;
return 0;
}$ gcc -std=c99 -Wall -Wextra -pedantic example.c -o example $ ./example
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#3 |
|
Professional Programmer
|
jakh, what compiler are you using?
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Aug 2007
Posts: 3
Rep Power: 0
![]() |
hi all,
Thanks everybody for quick reply, My compiler is gcc and I used the following options.(I have included the required header files etc..) gcc -g -Wall test.c yeah it should work , but I don't know why it gives such warnings. hey Jessehk, I copy and paste this code and tried , again it worked fine, Thank your for your help |
|
|
|
|
|
#5 |
|
Programmer
|
Does Test_read have the same declaration as the function pointer?
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Aug 2007
Posts: 3
Rep Power: 0
![]() |
yeah it is ...
please see the above code fragment. Thank you --jakh |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 2:12 PM |
| HELP please!!! | hamacacolgante | C | 7 | Nov 21st, 2005 5:36 AM |
| Pointers in C (Part II) | Stack Overflow | C | 2 | Apr 29th, 2005 10:39 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |