The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
why this pointer mismatch warning?
Discuss why this pointer mismatch warning? in the C Programming forum on Dev Shed. why this pointer mismatch warning? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 7th, 2003, 08:38 AM
|
|
.
|
|
Join Date: Dec 2002
Posts: 296
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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?
|

April 7th, 2003, 11:41 AM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
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.
|

April 7th, 2003, 12:31 PM
|
|
.
|
|
Join Date: Dec 2002
Posts: 296
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
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:
int strcmp(const char *s1, const char *s2); |
Quote: | This makes sense, since (if your K&R is the first edition) strcmp used to be defined as having parameters of type *void. |
no, it's from the 2nd edition.
Quote: | Anyway, I wouldn't worry about it too much. |
sounds good to me. thanks.
|

April 7th, 2003, 09:38 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
Quote: Originally posted by balance
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:
|
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.
|

April 8th, 2003, 12:18 PM
|
|
.
|
|
Join Date: Dec 2002
Posts: 296
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Quote: | check out the .h file. like for that strcomp i believe it is contained in string.h |
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: | 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. |
that's pretty useful - thanks.
|

April 8th, 2003, 12:45 PM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
Quote: | what about if you want to look at the actual strcmp implementation? or is that secret? |
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.
|

April 8th, 2003, 01:58 PM
|
|
.
|
|
Join Date: Dec 2002
Posts: 296
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Quote: | For example, here's the code for OpenBSD's implementation of strcmp(). |
oh yup, that's great. i'm using a bsd unix based system - so that's exactly what i was after. thanks.
|

April 8th, 2003, 03:03 PM
|
|
|
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. |
Actually, the source to the MS C runtime ships with the compiler/development environment and has for many years.
|

April 8th, 2003, 03:46 PM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
Not having done any Windows programming myself, I feared I'd get corrected on this one 
|

April 8th, 2003, 09:06 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
Quote: Originally posted by balance
what about if you want to look at the actual strcmp implementation? or is that secret?
|
= 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|