when to use size_t instead of an int?

This is a discussion on when to use size_t instead of an int? within the C++ Programming forums, part of the General Programming Boards category; I'm aware than unsigned int and size_t are usually equivalent, although size_t is less... operating system dependent for some reason. ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    106

    when to use size_t instead of an int?

    I'm aware than unsigned int and size_t are usually equivalent, although size_t is less... operating system dependent for some reason. I'm also aware that in some places, if you use either int or size_t, you convert type instead of compare.

    I'm not really sure WHERE I need to use one or the other. I'm primarily asking this because when messing around with some virtual machine code I found on gamedev, it used size_ts. Converting them all to int did not affect the code.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Use a size_t for array indices -- it's practically designed for such use.

    Use it with standard functions that return a value of this type, such as strlen.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 2
    Last Post: 03-24-2006, 07:36 PM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21