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

How do you list files in a directory?

805


With the help of using classes, write a program to add two numbers.

839


Why pointers are used in c?

755


what are the facialities provided by you after the selection of the student.

1929


Explain what are preprocessor directives?

817


What’s a signal? Explain what do I use signals for?

843


What is a pointer on a pointer in c programming language?

853


Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?

2424


Differentiate between the = symbol and == symbol?

926


Can you return null in c?

861


Explain what is the benefit of using an enum rather than a #define constant?

984


What extern c means?

738


What is the advantage of using #define to declare a constant?

845


will u please send me the placement papers to my mail???????????????????

1620


Is javascript based on c?

788