#include <iostream>
using namespace std;
#pragma pack(1) //
typedef struct {
uint8_t ID;
uint8_t CONFIG1;
} REG_MAP;
#pragma pack(0)
int main() {
REG_MAP* reg;
uint8_t arr[2] {1,2};
reg = (REG_MAP*) arr;
uint8_t temp = reg->ID;
cout << dec << reg->ID << endl;
cout << temp << endl;
if(temp == 1){
cout << "temp is 1" << endl;
}
printf("%d",reg->ID);
}
I tried to assign an array to a structure of the same size, but found that cout
could not print reg ID correctly, but printf()
could, which made me puzzled.
Aucun commentaire:
Enregistrer un commentaire