G
gamehack
Hi all,
As I was reading sizeof returns the size in units of char. So if
sizeof(int) == 4, it means int is 4 times as big as char =>
sizeof(char) == 1 (always). But malloc() is defined (from what I
googled) as allocating bytes. So malloc(1) will alocate one byte. But
on some systems a char can be 2/3/4 bytes. So really doing something
like:
char* p = malloc(1); for storing one character would not work. Or does
actually malloc allocate in units of char? And because char is 1 byte
on most system, people just assume that malloc allocates bytes? So what
do I do if I want a pointer to a byte in a portable way? Is it
possible?
Thanks
As I was reading sizeof returns the size in units of char. So if
sizeof(int) == 4, it means int is 4 times as big as char =>
sizeof(char) == 1 (always). But malloc() is defined (from what I
googled) as allocating bytes. So malloc(1) will alocate one byte. But
on some systems a char can be 2/3/4 bytes. So really doing something
like:
char* p = malloc(1); for storing one character would not work. Or does
actually malloc allocate in units of char? And because char is 1 byte
on most system, people just assume that malloc allocates bytes? So what
do I do if I want a pointer to a byte in a portable way? Is it
possible?
Thanks