Re: Warnings calling functions in other object files by pointer
From: Kevin Goodsell (usenet1.spamfree.fusion_at_neverbox.com)
Date: 12/30/03
- Next message: Ben Pfaff: "Re: Does this cause undefined behaviour?"
- Previous message: Joona I Palaste: "Re: Does this cause undefined behaviour?"
- In reply to: Kevin Goodsell: "Re: Warnings calling functions in other object files by pointer"
- Next in thread: Andrew Slade: "Re: Warnings calling functions in other object files by pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Dec 2003 22:25:43 GMT
Kevin Goodsell wrote:
> Andrew Slade wrote:
>
>> Hello,
>>
>> I am making calls from one compilation unit to functions in another by
>> pointers and I get the warnings below from gcc on 2.4.x Debian
>> Linux. The
>> executable seems to work fine but the warnings bothers me a lot, mostly
>> because I don't understand what I did wrong. The code I used I got
>> from the
>> FAQ on the matter, question 4.12.
>>
>> "warning: passing arg 2 of `hash_emumerate' from incompatible pointer
>> type"
>> "warning: passing arg 2 of `hash_free_table' from incompatible pointer
>> type"
>>
>> Compilation unit that is calling, stub.o
>> {
>> .
>> int printer(char *, void *data), (*printer_p)( char *, void *) = printer;
>> int strfree( void *d ), (*strfree_p)( void * ) = strfree;
>
>
> Note the return 'int' return types.
>
>> .
>> hash_enumerate( &table, printer_p);
>> .
>> hash_free_table( &table, strfree_p )
>> }
>> ================================================
>> Compilation unit that is being called, hash.o:
>>
>> void hash_free_table( hash_table *table, void (*func)(void *) )
>
>
> Here the second argument is for a function pointer with a 'void' return
> type, not 'int'.
>
>> {
>> ...
>> }
>> void hash_enumerate( hash_table *table, void (*func)(char *, void *) )
>
>
> Ditto.
>
>> {
>> ...
>> }
>> void printer(char *string, void *data)
>
>
> Redeclaration with a different return type.
>
>> {
>> ...
>> }
>> void strfree( void *d )
>
>
> Ditto.
>
> Also, the identifier 'strfree' is reserved for future use by the
> standard library <string.h> header (as are all identifiers beginning
> with 'str', 'mem', or 'wcs' followed by a lower-case letter). You should
> probably choose a different name.
>
I accidentally posted this prematurely. I meant to add this link, for
your information:
http://www.oakroadsystems.com/tech/c-predef.htm
This contains a list of reserved identifiers (in C and C++).
(I also meant to spell-check before posting. I don't see any obvious
spelling errors, but to me many spelling errors are non-obvious. ;) )
-Kevin
-- My email address is valid, but changes periodically. To contact me please use the address from a recent posting.
- Next message: Ben Pfaff: "Re: Does this cause undefined behaviour?"
- Previous message: Joona I Palaste: "Re: Does this cause undefined behaviour?"
- In reply to: Kevin Goodsell: "Re: Warnings calling functions in other object files by pointer"
- Next in thread: Andrew Slade: "Re: Warnings calling functions in other object files by pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|