What is size_t?
I've seen it everywhere, and I have no idea what it is. Im guessing it's a structure that comes with some library like iostream...
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++.
size_t is a type introduced by cstddef, it is an unsigned integer type that is the return type of the sizeof operator.
Wait, so your saying... I still don't get it. Pointers hold memory adresses, not values... But? DO I have to use size_t for sizeof()? God I'm lost...
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.
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.
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.
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.
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
Edit: Another post crept in, yeah i see what you mean ^^
ace
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement