Jump to content

  • Log In with Google      Sign In   
  • Create Account


The use of 'size_t'


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 BinaryPhysics   Members   -  Reputation: 294

Like
0Likes
Like

Posted 09 August 2012 - 07:51 AM

When reading back through my copy of "The C Programming Language" I noticed I'd missed a line that states that that the type 'size_t' is used only used for the return of the 'sizeof' operator and is only guaranteed to be large enough to hold the largest type size.

Why is it then that this type is used consistent when talking about conceptual size (like the size of an array or a file size)? I've seen it plastered all over the Internet and no-one has ever said anything against this kind of use...
[source lang="cpp"]# include <stdio.h>int main(int argc, char *argv[]){ size_t fsize = /* return the size of a previously opened file */; return 0;}[/source]
Can anyone clarify the use of such a type?

Edited by BinaryPhysics, 09 August 2012 - 07:52 AM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 29303

Like
2Likes
Like

Posted 09 August 2012 - 08:06 AM

is only guaranteed to be large enough to hold the largest type size

N.B. this includes arrays, so if I make an structure with an array of 10000 integers in it, and then make an array of 10000 of those structures, assuming that such an array is possible to create, then size_t has to be able to describe it's size in chars.

Also, in practice, SIZE_MAX is usually either UINT_MAX or ULLONG_MAX, depending on the native register size, so it makes a good "native sized unsigned integer" type.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS