CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

qsort uses 16-byte buffer for element swap

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

qsort uses 16-byte buffer for element swap
PostPosted: Mon Jan 28, 2008 10:52 am     Reply with quote

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
Ttelmah
Guest







PostPosted: Mon Jan 28, 2008 11:05 am     Reply with quote

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
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Mon Jan 28, 2008 11:24 am     Reply with quote

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
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Jan 28, 2008 11:59 am     Reply with quote

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.
Ttelmah
Guest







PostPosted: Mon Jan 28, 2008 3:28 pm     Reply with quote

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
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Tue Jan 29, 2008 8:56 am     Reply with quote

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 Smile

Ken
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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