I have a lot of problems understanding the concept of size_t and will really appreciate if anybody can help me understand the concept. I searched a lot on the net and went on a multiple forums and answers ranged from "it's an unsigned integer type" to the more bizarre "it is an unsigned data type which is the size of the microprocessors data-bus and helps in address arithmetic." Can somebody explain the concept simply enough? I read an article (http://www.embedded.com/electrical-engineer-community/industry-blog/4026076/1/Why-size-t-matters) on size_t and what I understood is that as integers have a fixed range and pointers also have a fixed range to hold the address, it cannot access variables beyond it's range i.e. if the size of the int is greater than the size of the pointer then there's a problem. I can't understand how size_t solves the problem and what should you use size_t for?
Jump to Post
It's for portability. The last paragraph of the link you posted explains it quite well. Given their example (the "I16LP32 processor"), let's assume we want to get the length of a C-string:
unsigned int length; length = strlen(str);
That's fine until the length of the string …
All 4 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.