🔒 Locked
size_t?
Advertisement
Original Post
I''m looking through some source code, and noticed a lot of use of size_t. What is it? After searching google, I can see that it''s used a lot, but no info on what it is or what it''s used for.
And is there an equivalent in C#? I''m attempting to convert the code to C# so it can be used with the rest of my .NET program.
Thanks.
-Nick
I''m pritty sure size_t is defined as the machines word size. (as in the real meaning of word - ie: the ''size'' of the register, eg, 4 bytes, 32 bit on a pentium 4, and 8 bytes, 64bit on an opteron)
So I dont think treating a size_t as an unsigned long in c# will work. - I''m also not familiure with C#.
So I dont think treating a size_t as an unsigned long in c# will work. - I''m also not familiure with C#.
in VC++, I believe size_t is equivalent to a LONGLONG (64 bit).
Is this correct?
I continually must typecast it into an (unsigned int) so I get no warnings for loss of precision (even though I KNOW my size is never that 4 gigs)...
Is this correct?
I continually must typecast it into an (unsigned int) so I get no warnings for loss of precision (even though I KNOW my size is never that 4 gigs)...
so much mystery surrounds this data type, i am ammused
quote:
Original post by superdeveloper
in VC++, I believe size_t is equivalent to a LONGLONG (64 bit).
Is this correct?
I continually must typecast it into an (unsigned int) so I get no warnings for loss of precision (even though I KNOW my size is never that 4 gigs)...
That''s because you''ve got the "64-bit portability" warning enabled. On a 64-bit platform, size_t will be 64 bits, which will be larger than unsigned int. An explicit cast silences that warning, but doesn''t make the code portable.
size_t is both the type returned by sizeof, and the type of array size/array index parameters.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
hmm better turn that off then...
Is 64-bit compatibility on by default? I don''t ever remeber modyfing that setting, but I use fread all the time, which returns a 64 bit size_t..
Is 64-bit compatibility on by default? I don''t ever remeber modyfing that setting, but I use fread all the time, which returns a 64 bit size_t..
quote:
Original post by superdeveloper
hmm better turn that off then...
Is 64-bit compatibility on by default? I don''t ever remeber modyfing that setting, but I use fread all the time, which returns a 64 bit size_t..
Yes, it''s on by default.
Note that your size_t *is* 32 bit, unless you''re targetting a 64 bit machine - it''s just warning you that this is a type whose size would change. It''s a portability warning, not a cross-compiling option.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement