Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > ccl and stl: design differences

Reply
Thread Tools

ccl and stl: design differences

 
 
jacob navia
Guest
Posts: n/a
 
      04-17-2011
In the ValArrays of the C containers library slices are defined
for an array and then ALL operations (indexing, searching, assigning
etc) will operate only in the slice, as if the other elements did
not exist.

In the STL the slice class is used with the overloaded operator[ ]
to obtain essentially the same effect as in C. Besides the absence of
overloaded operator [ ] in normal C, in C++ you have to manually
adjust the slice if the underlying array changes, i.e. if you
add or delete elements the slice will index a different set of
elements.

The C version avoids this since any modifications to the array will
also modify the slice accordingly.

Another difference is the behavior of the Max/Min functions. In
C++ making Max(array) with an empty array provokes undefined
behavior, and any result is valid.

In the C version I have tried to avoid undefined behavior
completely with a detailed error analysis. In this case
Max and Min return the identity element for those operations:
Max returns the smallest element storable in the underlying ValArray
type, Min returns the biggest element since

Max(a,smallest) ==> a for all a
Min(a, biggest) ==> a for all a

This is better than the undefined behavior in C++ in my opinion:
gcc returns zero for Max(empty_array). Zero is a very common value.

Another difference is the behavior of the Mismatch function. In the C
version if the arrays are of different length the smallest length
will be used. Elements will be compared, and if there is a difference
before the end of the smallest array that is the result. If there is no
difference and the smallest array is exhausted the result will be
one more than the length of the smallest array.

This means that there will be no crashes, as in C++

Please I do not mean to say that "C++ is bad" or similar nonsense.
The purpose of this post is to see if the C++ experts in this group
spot any errors in my reasoning. The C++ committee are bright people
and maybe I am missing something in the above examples.

jacob
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updates to the ccl jacob navia C Programming 35 07-07-2012 03:53 PM
CCL vs STL: a comparison jacob navia C Programming 29 05-12-2012 04:31 PM
Re: ccl HENRY Eshbaugh C Programming 3 08-30-2011 04:10 AM
New release of the C Containers Library (CCL) jacob navia C Programming 117 11-15-2010 04:12 PM
Re: New release of the C Containers Library (CCL) Jon C++ 16 11-09-2010 09:38 AM



Advertisments