C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 7th, 2003, 08:38 AM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old April 7th, 2003, 11:41 AM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
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.

Reply With Quote
  #3  
Old April 7th, 2003, 12:31 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old April 7th, 2003, 09:38 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
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.

Reply With Quote
  #5  
Old April 8th, 2003, 12:18 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old April 8th, 2003, 12:45 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
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.

Reply With Quote
  #7  
Old April 8th, 2003, 01:58 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #8  
Old April 8th, 2003, 03:03 PM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 272 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 17 h 57 m 24 sec
Reputation Power: 17
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.

Reply With Quote
  #9  
Old April 8th, 2003, 03:46 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
Not having done any Windows programming myself, I feared I'd get corrected on this one

Reply With Quote
  #10  
Old April 8th, 2003, 09:06 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > why this pointer mismatch warning?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap