Alex Rivera | Logout

is size_t always unsigned?

Asked 2009-07-06T20:55:39.003
75

As title: is size_t always unsigned, i.e. for size_t x, is x always >= 0 ?

Edit
Report

2 Answers

62

Yes. It's usually defined as something like the following (on 32-bit systems):

typedef unsigned int size_t;

Reference:

C++ Standard Section 18.1 defines size_t is in <cstddef> which is described in C Standard as <stddef.h>.
C Standard Section 4.1.5 defines size_t as an unsigned integral type of the result of the sizeof operator

answered 2009-07-06T20:56:41.593
14

Yes, size_t is guaranteed to be an unsigned type.

answered 2009-07-06T20:56:25.400

Your Answer