#gfdsgasdfasdf

22 messages · Page 1 of 1 (latest)

winter basaltBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

digital ridge
#

size_t is a typedef of some unsigned type

#

exactly which unsigned type size_t is a typedef of, depends on the computer and compiler

#

most likely it will be a 16-bit type on 16-bit machines, a 32-bit type on 32-bit machines, and a 64-bit type on 64-bit machines

#

size_t will always be the right size for the computer you're compiling for, and it will always match what's returned by sizeof

#

unsigned long can be 64-bit or 32-bit

#

if you're compiling on a 32-bit machine size_t will probably be either unsigned int or unsigned long and it will probably be 32 bits

#

if you're compiling on a 64-bit machine size_t will probably be either unsigned long or unsigned long long and it will probably be 64 bits

#

whatever the case, size_t will always be large enough to hold the size of any object

#

i feel like you're maybe overthinking this.
you don't really know ahead of time whether int is 16 or 32 bits, you don't know whether long is 32 or 64 bits, and you don't know whether the target computer is 16, 32, or 64-bit.
you do always know that long long is at least 64-bit, but you don't know whether that's an appropriate size to use.

#

size_t is the type used by sizeof and malloc and it usually uses the natural word size of the computer.

#

size_t might be 32 bits and long long int is always at least 64 bits

#

if you use long long it will make your program slow on 32 bit machines

#
  1. yes, size_t is the same as an unsigned /* something */ int, except for the fact that it's a typedef
  2. yes, when we say it's a typedef, there is literally a line in stddef.h that says typedef unsigned /* something */ int size_t
  3. you should use size_t instead of unsigned long long int because it might be smaller and faster
#

on a 16 bit computer, sizeof will return a 16 bit value, and size_t will be defined as a 16 bit type
on a 32 bit computer, sizeof will return a 32 bit value, and size_t will be defined as a 32 bit type

#

those two computers literally have different text in stddef.h

#

on your computer, #include <stddef.h> might put typedef unsigned long long size_t in your program. on a different computer, #include <stddef.h> might put in typedef unsigned int size_t instead

#

it's important to have the right one, because it is used to communicate with the OS. it's used to call a lot of functions like malloc.

winter basaltBOT
#

@sullen fjord Has your question been resolved? If so, run !solved :)

#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

winter basaltBOT
#

<@undefined>

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.