K
Kai Wu
#include <string.h>
#include <fstream>
#include <time.h>
typedef unsigned char BYTE;
struct Dex {
BYTE status;
struct timeval timestamp;
};
int main(){
ifstream in("FILE");
BYTE buf[9];
Dex d;
in.read((char*)buf,9);
while(in.good() && ! in.eof()){
memcpy(&(d.status),buf,1);
memcpy(&(d.timestamp),buf+1,8);
in.read((char*)buf,9);
}
}
Suppose FILE is a binary file with sequence of 9 bytes data, the 9 bytes
match the structure defined by Dex,
but above code fails to initialize the struct Dex as compiling with gcc,
with HP aCC it works.
is there something wrong with the code (or with gcc)? or is there a
better way to initialize the struct?
Thanks for your time.
#include <fstream>
#include <time.h>
typedef unsigned char BYTE;
struct Dex {
BYTE status;
struct timeval timestamp;
};
int main(){
ifstream in("FILE");
BYTE buf[9];
Dex d;
in.read((char*)buf,9);
while(in.good() && ! in.eof()){
memcpy(&(d.status),buf,1);
memcpy(&(d.timestamp),buf+1,8);
in.read((char*)buf,9);
}
}
Suppose FILE is a binary file with sequence of 9 bytes data, the 9 bytes
match the structure defined by Dex,
but above code fails to initialize the struct Dex as compiling with gcc,
with HP aCC it works.
is there something wrong with the code (or with gcc)? or is there a
better way to initialize the struct?
Thanks for your time.