How to avoid structure padding in C?

Answer Posted / lakshman naganoor

By #pragma

Example:
#pragma pack(push,1)
struct mystruct_A {
int b;
short d;
double c;
char m;
};
#pragma pack(pop)

main()

{
printf("size of structure mystruct_Ad is %d\n",sizeof
(struct mystruct_A));
}

size of structure mystruct_Ad is 15

Note:size of structure mystruct_Ad without using #pragma

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is calloc in c?

631


What is malloc and calloc?

550


What are enums in c?

626


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3705


Should I learn data structures in c or python?

558






What is advantage of pointer in c?

659


Why we use break in c?

523


What are the application of c?

622


What is the difference between call by value and call by reference in c?

592


How reliable are floating-point comparisons?

601


What is the usage of the pointer in c?

572


What do you mean by dynamic memory allocation in c? What functions are used?

625


How would you rename a function in C?

598


What is the difference between single charater constant and string constant?

594


Differentiate between static and dynamic modeling.

591