| | |
how do i sort reords from Z-A? (in turbo C)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
Originally Posted by Dave Sinkula
C++ Syntax (Toggle Plain Text)
int bar(const void *a, const void *b) { const int *x = a, *y = b; return (*x > *y) - (*x < *y); }
C++ Syntax (Toggle Plain Text)
int bar(const void *a, const void *b) { const int *x = (int*)a, *y = (int*)b; return (*x > *y) - (*x < *y); }
but otherwise an interesting algorithm.
Avoid compiling C code in a C++ compiler. (Or else save the file with a .c extension instead of .cpp!)
[edit] Yeah, I've been trying to Google the thing about 'no branches' or 'no instruction flush' or whatever it was -- something potentially beneficial to remember so that I could Google it again one day.
[edit=2]Here's another integer compare function that Narue might enjoy.
[edit=3]And note that in all my posts to this thread, the comparison function when used with qsort would sort in increasing order -- rather than the OP's requested decreasing order.
[edit]
•
•
•
•
but otherwise an interesting algorithm.
[edit=2]Here's another integer compare function that Narue might enjoy.
C++ Syntax (Toggle Plain Text)
int baz(const void *a, const void *b) { const int *x = a, *y = b; return (*x < *y) ? -1 : (*x > *y); }
[edit=3]And note that in all my posts to this thread, the comparison function when used with qsort would sort in increasing order -- rather than the OP's requested decreasing order.
Last edited by Dave Sinkula; Sep 19th, 2005 at 5:09 pm. Reason: Noting when I was finished editing.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>So why bother in that comparison function I posted ?
Because pointers to void can be funny beasties. I like to make sure that everything matches up before the function call on the off chance that I miss a subtle issue. That's actually a throwback from when I didn't fully understand pointers and wrote code to protect myself from my own ignorance, but at the very least it proves that I know what types strcmp expects.
>That will not compile with either VC++ 6.0 or Dev-C++. Requires cast like this
Try Turbo C, at least that way you won't accidentally compile as C++.
Because pointers to void can be funny beasties. I like to make sure that everything matches up before the function call on the off chance that I miss a subtle issue. That's actually a throwback from when I didn't fully understand pointers and wrote code to protect myself from my own ignorance, but at the very least it proves that I know what types strcmp expects.

>That will not compile with either VC++ 6.0 or Dev-C++. Requires cast like this
Try Turbo C, at least that way you won't accidentally compile as C++.
New members chased away this month: 4
![]() |
Other Threads in the C++ Forum
- Previous Thread: Porting from pc to MAC
- Next Thread: checking for a space bar input
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






