Can somebody tell me the difference between #pragma pack(push,1)
and __attribute__((packed))
? I am getting a compilation error if I use second type of struct packing which says
cannot bind packed field ‘ABC.abc::a’ to ‘unsigned int&’
But if I use first type of struct packing then there is no compilation error.
This is my sample code:
//DataStructure.h
#ifndef DATASTRUCTURE_H_
#define DATASTRUCTURE_H_
struct abc
{
unsigned int a;
float b;
}__attribute__((packed));
#endif /* DATASTRUCTURE_H_ */
//Main.cpp
#include<iostream>
#include<map>
#include "DataStructure.h"
int main()
{
struct abc ABC;
ABC.a=3;
ABC.b=4.6f;
std::map<unsigned int,struct abc> Mapp;
Mapp.insert(std::make_pair(ABC.a,ABC));
}