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

How is = symbol different from == symbol in c programming?

607


What is structure padding and packing in c?

612


Can we initialize extern variable in c?

626


What are the 5 types of organizational structures?

546


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

559






A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM

1695


write a program to copy the string using switch case?

2394


What are types of structure?

600


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

646


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

1207


What will the preprocessor do for a program?

583


How can variables be characterized?

1640


What are logical errors and how does it differ from syntax errors?

650


How do you redirect a standard stream?

618


Write a program to print fibonacci series without using recursion?

599