Results 1 to 6 of 6

Thread: int instead of size_t?

  1. #1
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default int instead of size_t?

    Why in anyone's name would trolltech decide to use int (or uint or whatever) instead of the great and portable size_t? I understand there's really no need and all, but for the elegance and future portablility such a change is really nothing?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: int instead of size_t?

    Isn't size_t a C (or even Posix/Linux/whatever) type? C++ doesn't use size_t, as far as I know.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: int instead of size_t?

    C++ does use size_t, and size_t is normally implemented on a platform basis. 'int' is bad form as it doesn't specify the size (it could be 8, 16, 32 or 64 bits, depending on platform), and can't be changed on a platform basis. eg. when 'int' is 16-bits, but it's perfectly acceptable to move > 64KB of data, you can't change it to 'unsigned long' easily where you can with size_t.

    Considering how much Qt is multi-platform, I am suprised it doesn't use size_t, but as of yet, I've not had a problem, as it's always ARM and above, so 'int' is always at least 32-bits.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: int instead of size_t?

    Quote Originally Posted by fatjuicymole View Post
    C++ does use size_t,
    True, I just grepped my includes

    Considering how much Qt is multi-platform, I am suprised it doesn't use size_t, but as of yet, I've not had a problem, as it's always ARM and above, so 'int' is always at least 32-bits.
    Maybe some (one?) of the supported platform does (used to?) have size_t defined incorrectly?

    BTW. It seems that Qt does use size_t in some places. So maybe this is just a mistake made in 4.0 and now it's all about providing backwards compatibility.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Angry Re: int instead of size_t?

    The reason I answer is pure rage.

    C++ does use size_t
    Of course there is std::size_t (in the header cstddef for instance), in fact its a very important builtin type and it exists since the first official standard from 1998.

    I cannot believe to see
    Qt Code:
    1. void QString::realloc(int alloc)
    To copy to clipboard, switch view to plain text mode 

    This is simply wrong, not just horribly bad, its wrong! I am now suffering from problems related to that - don't ask why there is a need for more than 2GB in a string, there just is.

    As I can see, all of Qt's code is full of such things, its horrible!

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: int instead of size_t?

    File a bug report. These things -do- get fixed, especially if you can provide a valid use case for the change.

    You also have the Qt source code, so you can make the change yourself if the wheels at The Qt Company turn too slowly for you.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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.