![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
qsort uses 16-byte buffer for element swap |
Posted: Mon Jan 28, 2008 10:52 am |
|
|
Please tell me if I've overlooked something before I jump all over CCS (again).
I'm having trouble with qsort (PCWH, V4.66). Looking at their stdlib.h, they use a 16-byte buffer for element swap in qsort.
So, if I try to sort things (array of struct) that are larger than 16 bytes, it messes up.
Am I missing something here?
Thanks,
Ken |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jan 28, 2008 11:05 am |
|
|
Why would you 'jump all over CCS'?. This is why they give you the _source code_ for functions like this. The assumption is that you will be able to modify it, if you want it to do something beyond it's basic abilities..
Yes, the default buffer is 16bytes. Making it larger on the smaller PIC's is a waste of space, since most applications will be for sizes less than this. The only 'error', is that the manual entry, should say that the function is limited to 16bytes as shipped, and if you want to swap larger elements, to increase the size of the buffer 't'.
It is a one line change, to make it as large as you want.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Mon Jan 28, 2008 11:24 am |
|
|
Yes, well . . .
I expect a standard library function like qsort(), which has been around forever, to work as documented, without restriction, on the intended target. The "element-swap" portion of qsort can use whatever buffer size the author deems appropriate - provided he accounts for elements larger than the buffer size!
Yes, I edited stdlib.h to use a larger buffer. qsort() still did not work properly, because the temp int variables are 8-bit (). I'm sorting 18 elements whose size is 21 bytes - not very demanding, but the product exceeds 8-bits. So I edited stdlib.h again. Works ok now.
Of course, with each compiler update, these edits will need redone, until ccs writes this standard library function properly.
Ken |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Jan 28, 2008 11:59 am |
|
|
It would be more froward thinking to copy the library function into another file in your project with a new name. Making a compiler upgrade should not be able to break your project.
As far as CCS changing library functions from efficient code to proper code without restrictions, that just seems like a bad path. Providing more than one version of functions would seem a less risky way to meet a variety of needs. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jan 28, 2008 3:28 pm |
|
|
OK.
The thing is that I don't ever really feel that CCS, 'has' libraries!...
It didn't have any library ability till recently (and there are still problems with this), and all it has are 'embedded' functions (like putc etc.), and a lot of code examples/templates. These are rarely really well written, with all having shortcomings if used outside fairly basic operations...
Now, I therefore treat functions like qsort, as the 'core' module, to use to help write the version to actually do your job, rather than something that is likely to work 'out of the box'. Rather 'snide', but I'm afraid a probably fairly realistic attitude to the CCS include files.
The real pity, is that the documentation is so poor (a continuous complaint with the CCS compiler), since if a function is restricted, then it should really be well documented as such. It is understandable that the standard function is restricted as it is, since the processor does not have any ability to dynamically assign data space. The memory allocation functions, require the space to be preallocated before use.
Realistically, it is an understandable restriction, but one that should be much better reported.
You don't have to change the include file. Make a copy of qsort, and include it in your code, after loading stdlib.h. Modify it as you want. Then change the data _type_ of one value (perhaps alter the 'qitems' counter to a long). Then the 'overloading' ability of the current compiler, will always use this, provided you ensure that the changed item data is always passed in the new type, rather than the standard definition. Makes it much safer.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Tue Jan 29, 2008 8:56 am |
|
|
Ttelmah -
I must admit to a poor choice of words here ("jump all over CCS")
That was just an expression, brought on by my frustration after finding why my program didn't work. I spent several hours trying to find what was wrong with my code. qsort is used in a couple places. In one place it worked just fine, but failed in the other, so - it had to be my code (but, no).
But, what I really meant was "before I submit a bug report" - which I have done, concisely and politely, as it should be. I'm really not a bad guy
Ken |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|