This question already has answers here:
What does 'unsigned temp:3' in a struct or union mean? [duplicate]
(4 answers)
Closed 7 years ago.
I'm browsing freebsd code and i see this:
i don't understand the use of colon in C
this is an example: u_char ip_hl:4, ip_v:4;
anyone have an idea?
These colons are used to set bit fields of structure members. u_char ip_hl:4 means u_char ip_hl can hold only up to 4 bits.
This is to do with Bit fields. You can learn more about it by reading here
Related
This question already has answers here:
What is the strict aliasing rule?
(11 answers)
Closed 6 years ago.
What really happens if we write 4 times 1B of char with 8bit pointer, and then we read that 4B with 32bit pointer? Why this is not recommended, what can happen?
When you read the 32bits back as an integer you get the integer representation of whatever you wrote.
What you have described is a technique commonly used to deserialize binary data. The reverse procedure will serialize the data.
This question already has answers here:
Can someone explain hex offsets to me?
(6 answers)
Closed 8 years ago.
I'm trying to understand what an offset in a hex dump is. In particular, what purpose does an offset serve? I have googled many times but not found anything.
The offset describes where something is in the file. You can obtain and jump to offsets in code using lseek(2) or fseek(3), depending on which I/O system you're using.
This question already has answers here:
Store and work with Big numbers in C
(3 answers)
Closed 8 years ago.
I want to store a number "x" where 0<=x<=(10^18).
Which datatype should be used in C for storing such a large number?
I used "long int" but it's not working..
Use unsigned long long int. It is supported in C99 or later, and as a compiler extension in some pre-1999 compilers. and it must be able to hold at least 1.8 * 10^19 values.
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How to convert struct to char array in C
Portable way of writing a C struct to a file (Serialisation for C)
I am looking for converting a structure to byte array in C and i was confused in doing that.Please show me a right way in achieving that. Thanks in advance.
A structure is a byte array. it starts at &mystruct and has the length of sizeof(mystruct_type) bytes.
If the binaries are to long or do contain gaps, check the #pragma pack settings.
hth
Maro
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is void* and to what variables/objects it can point to
What does void* represent in C?
Please give a reason for the use, too...
void * is a "typeless" pointer in C, that is, a pointer that may point to an object of any type. It is used if one does not know the type of the data to be stored beforehand.