GCC -Wpadded不提供任何警告 [英] gcc -Wpadded does not provide any warning

查看:836
本文介绍了GCC -Wpadded不提供任何警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用gcc的-Wpadded选项知道是否GCC能帮助我找到了一个结构是否填充与否。这是下面的code。

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;
}

我遵守使用下面的code。 GCC -Wpadded alignment_demo.c 。它没有返回任何警告。所以,我的结构不填充或者我失去了一些东西? 男人的gcc 但是说明它支持一种名为-Wpadded的选项。好心帮

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

推荐答案

似乎包结构默认为 - 4。( GCC -fpack-结构= 4

如果这样 - 比这个结构已经对准结果。
因为

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]

由于的 INT

这篇关于GCC -Wpadded不提供任何警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆