收到有关压缩结构的意外编译警告
Got unexpected compile warning about packed structure
当我运行以下代码片段时,收到了警告,不知道为什么。g++的版本为4.8.4。
$ g++ -g -fPIC -std=c++11 -fpermissive te.cc
te.cc:25:11: warning: ignoring packed attribute because of unpacked non-POD field ‘cMacAddr strArp::src_hw_mac’ [enabled by default]
cMacAddr src_hw_mac;
^
te.cc:27:11: warning: ignoring packed attribute because of unpacked non-POD field ‘cMacAddr strArp::dst_hw_mac’ [enabled by default]
cMacAddr dst_hw_mac;
代码段"te.cc"
#include <iostream>
#include <utility>
#include <functional>
#include <string>
using namespace std;
typedef unsigned char uchar;
typedef unsigned short uint16;
typedef unsigned int uint;
char _ethHdrPrintBuf[100];
class cMacAddr {
public:
uchar addr[6];
cMacAddr() { for (int i=0; i<6; i++) addr[i] = 0;}
};
struct strArp {
uint16 hw_type;
uint16 proto_type;
uchar hw_size;
uchar proto_size;
uint16 opcode;
cMacAddr src_hw_mac;
uint src_proto_ipv4;
cMacAddr dst_hw_mac;
uint dst_proto_ipv4;
} __attribute__((__packed__ )) ;
int main()
{
cout << sizeof(strArp) << endl;
return 0;
}
cMacAddr
有一个构造函数,因此它不能是POD。这里的细节太多了。
相关文章:
- 二叉排序树无法编译
- 编译时未启用intel oneApi CUDA支持
- vscode下的Arduino代码出现意外编译错误
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- 函数调用中出现意外编译错误 (C++)
- C++中出现意外的编译错误:将默认值传递给函数参数
- 错误 : 尚无法编译此意外的强制转换值
- 已编译的 protobuf 文件的意外输出路径
- 无法编译顶点着色器:令牌"<EOF>"出现意外$end
- 传递引用匿名实例时出现意外编译错误
- 在我的Mac OSX El Capitan上编译带有意外错误的简单C++类
- 获取0:1(1):错误:语法错误,尝试编译着色器时意外$end
- 意外的模板实例化导致编译错误
- 收到有关压缩结构的意外编译警告
- #include在查找预编译头文件时跳过——查找预编译头文件时意外结束
- 使用clang优化编译时得到意外结果
- 代码意外编译失败.为什么
- 在Visual Studio 2012中,作用域操作符中的错别字会导致意外的编译和递归
- 在visual studio中编译意外的(未声明的标识符)错误
- 编译 moc 文件 Qt 4.5.2 intrin.h 意外类型 "void" Visual Studio 2015