This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: More fortran dir warning fixes


 > From: Jeffrey A Law <law@cygnus.com>
 > 
 >   >        name = bsearch ("foo", &names[0], ARRAY_SIZE (names), sizeof (names[
 >   > 0]),
 >   > -		      (int (*)()) strcmp);
 >   > +		      (int (*)(const void *, const void *)) strcmp);
 > I get a little worried when we have to cast system level function pointers
 > like this.  What precisely about strcmp is causing problems?
 > jeff

Well there's two things, why cast at all, and why did I add the
arguments.  (I think you meant the first one, but I'll answer both.)

Regarding the first question, you need some sort of cast because the
prototype for strcmp is "int(*)(const char *, const char *)" and
bsearch is expecting const void * arguments.  Gcc complains when you
pass it strcmp without any cast at all.

 > warning: passing arg 5 of `bsearch' from incompatible pointer type  

Regarding the second question, I added arguments to the cast because
-Wstrict-prototypes didn't like it without them.

 > warning: function declaration isn't a prototype

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]