c++

can anyone tell me,,,,,,,
1-what is use of bit field in structure and why we use.
2-how we know our system is little endian or big endian
3-if i allocate memory using malloc then can i use delete to deallocate the memory.
Thanx
Last edited on
Well I'll answer the last one, you have to use free to allocate the memory from malloc, you can't use delete. It MIGHT work, but it's not correct to do it. You should use C DMA functions or C++ DMA functions, not interchange them.
I will answer to the 1st question:
A bit field is a class containing member with an user defined size:
1
2
3
4
5
6
struct eg
{
    int smallnumber : 16;// 16 is the size in bits
    int evensmaller : 15;
    bool singlebit : 1;
};

By using this you are able to use variable with your own memory size (It shouldn't be larger than 32 bits)
Last edited on
#1 - it is used to allow direct access to individual bits without having to deal with bitmasking.

#2 - Assuming you are using 32-bit, write the integer 0x01020304 to a variable,
take a pointer to the value, cast it to a char pointer, and check to see if
the referenced byte is 0x01 (big endian) or 0x04 (little endian).

#3 - You should not use delete to free memory allocated by malloc even if it
works. (Likewise with new/free). To jpeg, I understand what you are
saying, but be careful of your use of the term DMA because this has
nothing to do with direct memory access.

Topic archived. No new replies allowed.