Results 1 to 2 of 2

Thread: Qwt 6: moving to size_t (unsigned) integer type for sizes and indexes was unfortunate

  1. #1
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qwt 6: moving to size_t (unsigned) integer type for sizes and indexes was unfortunate

    There was so much great software engineering cleanup in Qt 6 and 6.1. Really quite excellent.

    But one thing I was sorry to see was the move to unsigned integers (size_t) for size and index values, for example in these analogous methods:


    • Qwt5: int QwtPlotCurve::dataSize() const;
    • Qwt6: size_t QwtSeriesStore<T>::dataSize() const;


    I regard size_t as an historical mistake. Any value to which subtraction would be applied really should be signed. Note that making an integer unsigned of course doesn't protect against it being assigned what is (or should be) a negative value -- it only guarantees that if that happens, the result is a sometimes difficult-to-detect disaster.

    It's not uncommon to assign (-1) to an undefined index variable. That can be recognized regardless of the size of the array to which it would be applied -- BUT ONLY if we sacrifice one little single bit to allow the representation of negative numbers. Note that a <size_t> value is NEVER < 0 (even if it is) -- a very likely coding mistake, resulting in invalid memory references -- or an infinite loop -- i.e. disaster.

    And when applying dynamic offsets to an index, the result could certainly be negative, and the only way to detect that is to get your hands on the size of the array to which it would be applied, and using a non-intuitive expression, (>= size), for this condition.

    Qwt5's choice of a (signed) int, as is used in Qt proper, for these values was better. $0.02 (and then some).
    Last edited by philw; 4th October 2015 at 22:51.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt 6: moving to size_t (unsigned) integer type for sizes and indexes was unfortu

    Your observation is not 100% correct: size_t is inherited from Qwt5 ( AFAIR even earlier, see the history of QwtData ) invented at a time when Qt containers where also using unsigned. All what has been done in Qwt6 is to fix the inconsistent API of a wrapping method.
    When Qt development came up with a new template library it was not possible to simply adjust Qwt - remember Qwt5 supports Qt3/Qt4.

    But I agree, that using integers has become standard since Qt4 and it could be changed in Qwt as well.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    philw (5th October 2015)

Similar Threads

  1. int instead of size_t?
    By rubenvb in forum Qt Programming
    Replies: 5
    Last Post: 27th April 2017, 19:51
  2. Replies: 0
    Last Post: 24th May 2010, 12:19
  3. using directive and size_t in loop for
    By mickey in forum General Programming
    Replies: 5
    Last Post: 15th April 2008, 12:33
  4. Conversion from unsigned char* to unsigned char
    By santosh.kumar in forum General Programming
    Replies: 1
    Last Post: 6th August 2007, 13:12
  5. converting string to unsigned integer
    By mgurbuz in forum Qt Programming
    Replies: 4
    Last Post: 12th May 2006, 09:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.