I am trying to use gcc's -Wpadded option to know if gcc can help me in finding out whether a structure is padded or not. This is the following code.
#include<stdio.h>
struct my {
char *name;
int age;
} my_details;
int main() {
struct my person1;
return 0;
}
I complied the code using the following. gcc -Wpadded alignment_demo.c
. It did not return any warnings. So is my structure not padded or I am missing something? man gcc
however shows it supports an option called -Wpadded. Kindly help
Thanks Chidambaram
GCC 4.3+ now has -Q --help=warnings , and you can even specify --help=warnings,C to just print out the C related warnings.
-Wno-coverage-invalid-line-number can be used to disable the warning or -Wno-error=coverage-invalid-line-number can be used to disable the error. Suppress warning messages emitted by #warning directives.
To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
Seems that pack struct default is - 4. (gcc -fpack-struct=4
)
If it so - than this structure is already aligned.
Because
char* - 4 or 8 bytes
int - 4 bytes
If you run this, you will have warning:
azat:~$ gcc -Wpadded -fpack-struct=8 -o test /tmp/test.c
/tmp/test.c:6:1: warning: padding struct size to alignment boundary [-Wpadded]
Because of the int
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With