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;
..
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 *) )
{
....
}
void hash_enumerate( hash_table *table, void (*func)(char *, void *) )
{
....
}
void printer(char *string, void *data)
{
....
}
void strfree( void *d )
{
....
} 5 1822
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; .. 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 *) ) { .... } void hash_enumerate( hash_table *table, void (*func)(char *, void *) ) { .... } void printer(char *string, void *data) { .... } void strfree( void *d ) { .... }
The hash_enumerate() function expects a pointer to a function returning
void, but you provide a function returning int. Same thing for the
hash_free_table() function.
HTH
Bjørn
--
The worlds fastest web server is now available
at http://highlander.metasystems.no:2000. Enjoy!
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"
The code you posted does not tell us what prototype the calling TU has for
the called functions. However, ...
int printer(char *, void *data), (*printer_p)( char *, void *) = printer;
[...] hash_enumerate( &table, printer_p);
printer_p returns an int here, while
void hash_free_table( hash_table *table, void (*func)(void *) )
the second argument to hash_free_table and hash_enumerate returns void.
This is a clear mismatch
--
Martin Ambuhl
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.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
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.
Thank you all for you answers. I had blindly followed the FAQ example that
showed functions returning "int" and had decided the process involved
casting all pointers to "int"s. Somehow, sort of...
Anyway, thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andreas Lagemann |
last post by:
Hi,
after browsing FAQ and archive for a while I decided that the following
is a legal question.
Consider this:
Class Base
{
public:
Base() {}
|
by: Francesco Bochicchio |
last post by:
Hi all,
anybody knows if there is a (standard, portable) way to dinamically build
a list of parameters to call a C function? Something like va_start & co,
but to be used on the calling side?
...
|
by: cody |
last post by:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.
i heard people say C++ is slower than C but i can't...
|
by: Charlie Zender |
last post by:
Hi,
I am unable to compile a large body of code with extremely pedantic
compile time checks activate, so that warnings cause errors.
With GCC 3.3.1, I do this with
gcc -std=c99 -pedantic...
|
by: Deniz Bahar |
last post by:
Hi,
I would like to call one of my functions the exact name as an existing
C library function (for example K&R2 exercises asks me to make an atof
function). If I don't include the header with...
|
by: Ross A. Finlayson |
last post by:
Hi,
I hope you can help me understand the varargs facility.
Say I am programming in ISO C including stdarg.h and I declare a
function as so:
void log_printf(const char* logfilename, const...
|
by: Lindsay |
last post by:
I'm getting some strange warnings when I compile:
pointer truncation from 'HMENU' to 'unsigned int'
The line in question is:
AppendMenu(hMenu,MF_STRING|MF_POPUP,UINT(hStyle),"Style");
(where...
|
by: thibault.langlois |
last post by:
Hello,
I get a warning when I compile:
#include <string.h>
int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}
|
by: markn |
last post by:
Running some code through static analysis, I noticed that gcc will
generate a warning if a function returns an aggregate, controlled with
this flag (from the gcc manual):
-Waggregate-return...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |