|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
why this pointer mismatch warning?
some code from a book gives this warning when i compile it:
warning: pointer type mismatch in conditional expression the line that's warned about is: Code:
qsorty((void **) lineptr, 0, nlines-1, (int (*)(void *, void *))(numeric ? numcmp : strcmp)); so it would indicate that there's something up with this bit maybe : numeric ? numcmp : strcmp the code does work, so maybe it doesn't matter? but i'm wondering why i get the warning. it's from the k&r book which seems to be generally pretty accurate and correct. i'm fairly sure i've typed it in correctly. 2 decleration lines that appear before the above line, that might be usefull to see are : Code:
void qsorty(void *lineptr[], int left, int right, int (*comp)(void *, void *)); int numcmp(char *, char *); why does it give a warning? |
|
#2
|
||||
|
||||
|
Well, on my Linux box, strcmp appears to have the following prototype:
Code:
int strcmp(const char *s1, const char *s2); So it's probably complaining about the type mismatch of the functions parameters. This makes sense, since (if your K&R is the first edition) strcmp used to be defined as having parameters of type *void. Anyway, I wouldn't worry about it too much.
__________________
"A poor programmer is he who blames his tools." http://analyser.oli.tudelft.nl/ Last edited by Analyser : April 7th, 2003 at 12:58 PM. |
|
#3
|
|||||
|
|||||
|
where is the source code for the already-written-for-you functions? or how do you go about finding that out? - to find out stuff like:
Quote:
Quote:
no, it's from the 2nd edition. Quote:
sounds good to me. thanks. |
|
#4
|
||||
|
||||
|
Quote:
check out the .h file. like for that strcomp i believe it is contained in string.h . another great source is msnd.com. all u do is type in the function name, strcmp() and it will return a whole bunch of useful stuff describing it. edit: here check out this link for strcmp() on MSDN. strcmp Last edited by infamous41md : April 7th, 2003 at 09:43 PM. |
|
#5
|
||||
|
||||
|
Quote:
oh yeah, it says Code:
int strcmp __P((const char *, const char *)); for strcmp. what about if you want to look at the actual strcmp implementation? or is that secret? Quote:
that's pretty useful - thanks. |
|
#6
|
||||
|
||||
|
Quote:
That's the difference between open source and proprietary software There's no way of finding out (other than becoming a programmer for Microsoft, obviously) to know how MS have implemented the strcmp() function in their C library.The source code for the GNU C library, though, is freely available, as is the code for most *BSD Unix C libraries. For example, here's the code for OpenBSD's implementation of strcmp(). Oh, and the site that infamous41md recommended is actually msdn.com, MSDN being short for MicroSoft Developer Network. On most unix systems, you can type man <function_name> at the prompt to get a description for a function. YMMV. |
|
#7
|
|||
|
|||
|
Quote:
oh yup, that's great. i'm using a bsd unix based system - so that's exactly what i was after. thanks. |
|
#8
|
|||
|
|||
|
Quote:
Actually, the source to the MS C runtime ships with the compiler/development environment and has for many years. |
|
#9
|
||||
|
||||
|
Not having done any Windows programming myself, I feared I'd get corrected on this one
![]() |
|
#10
|
||||
|
||||
|
Quote:
= i was just thinkin.... im pretty sure if u look at the disassembled code u could get a pretty good idea of how strcmp() works? when i get to my other comp. i will try it out. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > why this pointer mismatch warning? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|