How to avoid structure padding in C?

Answer Posted / santosh

Packing, on the other hand prevents compiler from doing padding - this has to be explicitly requested - under GCC it's __attribute__((__packed__)), so the following:

struct __attribute__((__packed__)) mystruct_A {
char a;
int b;
char c;
};

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 5 types of organizational structures?

550


How can I automatically locate a programs configuration files in the same directory as the executable?

632


simple program of graphics and their output display

1469


write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.

1983


One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2160






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

608


What are static variables in c?

629


What are the advantages of using Unions?

642


What is nested structure in c?

614


How do we print only part of a string in c?

587


Where local variables are stored in c?

557


Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)

5806


Difference between macros and inline functions? Can a function be forced as inline?

712


Why is it that not all header files are declared in every C program?

683


Can we compile a program without main() function?

634