Skip to main content
Advice
2 votes
0 replies
0 views

How malloc() assigns the value to the allocated memory?

Uh. Each byte has 8 (eight) bits (on a typical general-purpse CPU). You are assigning each of your 4 (four) bytes (4*8==32 bits total) a value that consists of 5 (five) one-bits and 3 (three) zero-...
Igor Tandetnik's user avatar
Advice
2 votes
0 replies
0 views

How malloc() assigns the value to the allocated memory?

Two (unrelated) things: sizeof(char) is defined by the C specification to always be equal to 1 (no matter the actual sizer in bits of char); For any pointer (or array) p and index i, the expression *(...
Some programmer dude's user avatar
Advice
1 vote
0 replies
0 views

How malloc() assigns the value to the allocated memory?

Side notes, sizeof(char) is defined as 1 and so it can be omitted (though learning to always include the size as part of the size argument is helpful). Also, *(mmry_ptr+i) is simply mmry_ptr[i], the ...
David C. Rankin's user avatar
1 vote

Is it possible to use a character array as a memory pool without violating strict aliasing?

As of C23, this is indeed undefined behavior. If you want to store objects of another type in a char array, you would have to use memcpy for every reading and writing access. But this will change in ...
dpi's user avatar
  • 2,138
Best practices
1 vote
0 replies
0 views

How to properly serialize raw binary data in C/C++?

One big problem with binary serialization is when you have to deal with different endian representations between the serializer and deserializer. In such an environment it almost impossible to just ...
Thibe's user avatar
  • 762

Only top scored, non community-wiki answers of a minimum length are eligible