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 the purpose of void pointer?

686


What are actual arguments?

736


Difference between pass by reference and pass by value?

740


What is the explanation for prototype function in c?

649


How do you construct an increment statement or decrement statement in C?

862






write a proram to reverse the string using switch case?

2560


How can I handle floating-point exceptions gracefully?

743


How can I access an I o board directly?

727


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

820


What is a keyword?

856


A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?

1604


Is register a keyword in c?

737


What is pointer to pointer in c?

745


What is structure of c program?

693


What is the scope of static variables in c language?

732