Jump to content
  • Advertisement
Sign in to follow this  
dbzprogrammer

What is size_t?

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
size_t in C and ::std::size_t in C++ are typedefs of built-in unsigned integral types which are defined to be the datatype which a sizeof expression yields. There are several standard files you can include in C and C++ to have access to size_t, but most-commonly it is recommended that you include <stddef.h> in C or <cstddef> in C++.

Share this post


Link to post
Share on other sites
size_t is a type introduced by cstddef, it is an unsigned integer type that is the return type of the sizeof operator.

Share this post


Link to post
Share on other sites
Was this type really worth creating for the sake of sizeof() or is its use more widespread?

ace

Share this post


Link to post
Share on other sites
Is it just me or did a post lose its way somewhere in there?

Anyway, in answer to dbzprogrammer -- a pointer, in C++, is one of the many kinds of variables that exist, and the purpose of a variable (in C++) is to hold a value. The kinds of values that pointers hold are numerical addresses into memory, but they are values nonetheless. This is why you can do shifty things like pointer arithmetic with them.

Share this post


Link to post
Share on other sites
Quote:
Was this type really worth creating for the sake of sizeof() or is its use more widespread?


What would you have sizeof return? Creating a type like that is the typesystem equivalent of using a pointer to indirectly refer to a variable. It is a Good Thing.

Quote:
Is it just me or did a post lose its way somewhere in there?


He's replying to a post that has been deleted.

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
Was this type really worth creating for the sake of sizeof() or is its use more widespread?

Well, in theory it should be an unsigned integer of pointer size. Also, in theory the pointer size should equal the processor word size (16 bits on a 16-bit processer, 32 bits on a 32-bit processor, 64 bits on a 64-bit processor). If that assumption is correct, it would be quite useful in many scenarios.

Share this post


Link to post
Share on other sites
But if size_t is actually an unsigned int then why not have sizeof() return an unsigned integer. Or is it simply because at some point a redefinition of size_t might happen and therefore anyone who has coded it properly will be fine?

Edit: Another post crept in, yeah i see what you mean ^^
ace

Share this post


Link to post
Share on other sites
Arg, I know that already... They hold memory adress values, but from what im understanding size_t's don't. Plus when you do arithmatic you basically add a couple bytes until your offset is fullfiled

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!