Mail Archives: djgpp/1996/05/09/16:49:42
Gert-Jan Schoenmakers (tgtcgs AT tc0 DOT chem DOT tue DOT nl) wrote:
: I've recently switch from Microsoft C/C++ 7.0 to djgpp 2.0 for
: developping signal processing software. Now I have a trouble reading
: binary data files which consist of a header and an amount of data. The
: recent discussion about the sizeof(int) was a first step in solving the
: problems I had (I redifined the int's to short int's) but now I'm stuck.
: The MSC compiled program tells me sizeof(struct header)=98 and the DJGPP
: compiled program tells me sizeof(struct header)=100.... Can someone help
: me out on this one ????
: J.H.A. Schoenmakers
: Ph.D. student Eindhoven University of Technology
: Faculty of chemistry & chemical engineering
: e-mail:tgtcgs AT chem DOT tue DOT nl
: struct header {
: short int shift;
: short int ied;
: short int units;
: short int coll_mode;
: short int rejection;
: short int clock_source;
: short int coin;
: short int qfactor;
: short int anode_crt;
: short int burst_detect;
: short int buffer_mode;
: short int at_base;
: short int osize_reject;
: short int output_data_fmt;
: short int hv_on_off;
: short int fl;
: long num_samples;
: long bursts_req;
: long bursts_val;
: float data_rate;
: float duty;
: float dead;
: float calib;
: float recint;
: float pos[3];
: float shifter;
: short int manual_shift;
: short int timeout;
: short int data_valid;
: short int rec_len;
: short int gain;
: short int attn;
: short int hv;
: short int span_index;
: short int center_index;
: }*head;
: }
: head = (struct header *)malloc(sizeof(struct header));
: fprintf(stderr,"Sizeof header = %d\n",sizeof(struct header));
This is because the last list of short ints has an odd number of elements.
Since structs are padded to multiples of sizeof(int), this means that a final
short int is added to make it a multiple of 4. To fix this, either use
fread with a length of 98 instead of sizeof(struct header) or add a short int
dummy parameter and load the struct with length offsetof(struct header,dummy).
As long as the elements in the structure are not reorganized, it should work,
if it doesn't, you have to read the structure elements manually.
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows
alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (plain) | you're a dog."
<URL:http://www.student.informatik.th-darmstadt.de/~alexlehm/>
- Raw text -