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-...
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 *(...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c × 408304c++ × 40619
arrays × 30472
linux × 29945
pointers × 28472
gcc × 16008
struct × 14687
string × 14279
sockets × 8779
function × 7955
windows × 7813
malloc × 7756
multithreading × 7208
file × 6960
scanf × 6652
linked-list × 6384
assembly × 6367
segmentation-fault × 6341
printf × 5993
python × 5927
memory × 5906
algorithm × 5839
winapi × 5430
unix × 5348
char × 4939