ccl and stl: design differences

Discussion in 'C Programming' started by jacob navia, Apr 17, 2011.

  1. jacob navia

    jacob navia Guest

    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

    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 navia, Apr 17, 2011
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jacob navia

    New release of the C Containers Library (CCL)

    jacob navia, Oct 30, 2010, in forum: C Programming
  2. Jon
  3. HENRY Eshbaugh

    Re: ccl

    HENRY Eshbaugh, Aug 29, 2011, in forum: C Programming
    HENRY Eshbaugh
    Aug 30, 2011
  4. jacob navia

    CCL vs STL: a comparison

    jacob navia, May 11, 2012, in forum: C Programming
    Jens Gustedt
    May 12, 2012
  5. jacob navia

    Updates to the ccl

    jacob navia, Jun 7, 2012, in forum: C Programming
    Malcolm McLean
    Jul 7, 2012

Share This Page