Thread: when to use size_t instead of an int?

  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,005
    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, 08: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-02-2003, 12:26 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM