Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 16th, 2007, 2:14 PM   #1
jakh
Newbie
 
Join Date: Aug 2007
Posts: 3
Rep Power: 0 jakh is on a distinguished road
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]
jakh is offline   Reply With Quote
Old Aug 16th, 2007, 2:54 PM   #2
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline   Reply With Quote
Old Aug 16th, 2007, 3:16 PM   #3
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
jakh, what compiler are you using?
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Aug 16th, 2007, 10:32 PM   #4
jakh
Newbie
 
Join Date: Aug 2007
Posts: 3
Rep Power: 0 jakh is on a distinguished road
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
jakh is offline   Reply With Quote
Old Aug 16th, 2007, 10:58 PM   #5
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
Does Test_read have the same declaration as the function pointer?
niteice is offline   Reply With Quote
Old Aug 16th, 2007, 11:05 PM   #6
jakh
Newbie
 
Join Date: Aug 2007
Posts: 3
Rep Power: 0 jakh is on a distinguished road
yeah it is ...
please see the above code fragment.
Thank you

--jakh
jakh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC