- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problem with qsort
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 06:18 AM
05-07-2004 06:18 AM
cc: warning 604: Pointers are not assignment-compatible. cc: warning 563: Argument #4 is not the correct type.
This is the line of code:
qsort(usocs, 18, sizeof(usocs[0]), strcmp);
I have included
To fix I have even tried declaring a function pointer and assigning the strcmp function to it:
int (*fn_pointer) (const void *, const void *);
fn_pointer = strcmp;
qsort(usocs, 18, sizeof(usocs[0]), fn_pointer);
When I compile this fix I get the following compiler warning for the line "fn_pointer = strcmp;":
cc: warning 604: Pointers are not assignment-compatib
le.
According to what I have read, this fix should work.
Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 06:32 AM
05-07-2004 06:32 AM
Re: Problem with qsort
You could try to add the prototype in your code:
int strcmp(const void*,const void*);
That should fix it, or tell you where the real prototype is defined.
Or you could just ignore it, as it is just a warning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 07:18 AM
05-07-2004 07:18 AM
Re: Problem with qsort
I no longer got a warning message on the qsort line itself.
The strcmp function is used other places in the program and those lines are not being flagged, so I know that the compile/link can find strcmp in
I added the following line just to be sure:
int strcmp(const void*,const void*);
So it appears that the problem is just with the statement: fn_pointer = strcmp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 08:02 AM
05-07-2004 08:02 AM
Solutionqsort(usocs, 18, sizeof(usocs[0]),strcmp);
should be:
qsort((void *) usocs,(size_t) 18,sizeof(usocs[0]),
(int (*)(const void *a, const void *b))strcmp);
If I've done counted my paren's right, that there ought to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 08:39 AM
05-07-2004 08:39 AM
Re: Problem with qsort
A couple of questions though:
I'm not familiar with size_t.
What is it and why do I need it?
Do you know why I was getting the
"cc: warning 604: Pointers are not assignment-compatible" warning when trying to assign: "fn_pointer = strcmp;" in my previous fix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 08:52 AM
05-07-2004 08:52 AM
Re: Problem with qsort
The type cast was also the problem with your fn_pointer assignment so the same fix will fix you there and would not then require the type cast in the qsort actual parameters.
int (*fn_pointer)(const void *a, const void *b) = NULL;
fn_pointer = (int (*)(const void *a, const void *b)) strcmp;
qsort((void *) usocs,(size_t) 18, sizeof(usocs[0]),fn_pointer);
I hope I've counted them paren's right again cause it gets to be a mite tricky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 09:04 AM
05-07-2004 09:04 AM
Re: Problem with qsort
Great explanation. Thanks for the help!