Re: Utilty for parsing raw data into C structures

From: Pat Ford (pat.ford_at_nrc.ca)
Date: 09/30/04


Date: Thu, 30 Sep 2004 07:25:02 -0400


"Nils O. Selåsdal" <NOS@Utel.no> wrote in message
news:9eP6d.12593$g%5.162430@news2.e.nsc.no...
> Pat Ford wrote:
> > "Karthik K R" <shukart1@yahoo.com> wrote in message
> > news:44bd5fac.0409290606.69a9d264@posting.google.com...
> >
> >
> >
> >
> > how about;
> >
> > //================== in the header file
> > typedef struct {
> > u_int16_t jmp_opcode; // this is always a 6
> > u_int16_t Buffer; // the is the offset for the satrt of the
main
> > program
> > u_int16_t Naddr; // number of addresses in the setup section
> > u_int16_t CASES; // the number of cases in the program
> > u_int16_t highChannelBitmap; // channel addresses in the range of
E940
> > to E95A
> > u_int16_t lowChannelBitmap; // channel addresses in the range of
E740
> > to E75A
> > u_int16_t subcases; // the number of subcases of option 0xD
> > u_int16_t spare; // unused
> > u_int16_t FUNCT[8]; // starting addresses of upto 8 functions this
is
> > an offset from tble
> > HomeType home[20]; // this array hold the value and address for
each
> > "safe"
> > // position. the number comes from refer.h AddressTableLimit
> > u_int16_t poo[16];
> > }RefHeaderType;
> Depending what's the structure of the data is in
> }RefHeaderType __attribute__((__packed__));
> might be needed when mapping data directly to C structures.

 Good catch, the latter revisions of this system use the packed attribute.
As a note to others, packed forces the compiler to do what you think when
you use a structure, not align it on word. quadword or other boundaries.
This becomes important if your structure is accessed by a program that was
built with a different compiler.
 In my case this structure goes on to a reflective memory network, it is
built on redhat9 has an NT and a W98 client and a few other RH9 machines all
reading it. Not using the packed allowed the structure to work great on all
RH9 but fail on the others and caused a week of headaches.
Pat



Relevant Pages

  • Re: object system...
    ... or at least until more code needs to be built around ... for a compiler the program is a text. ... the statically-compiled parts of the app tend to be ... formalisms don't matter so much as long as the code is working... ...
    (comp.object)
  • Re: Compilation on VS 2005 Beta 2 is slower than on VS 2003
    ... using the previous built of this same product... ... Every version of Delphi ... >>> We never ship Betas with debug code of symbols. ... >>> I personally haven't noticed this and we are using VS 2005 compiler to ...
    (microsoft.public.vsnet.general)
  • Re: PHP compiler
    ... >built in functions. ... But, anyway, my compiler doesn't have to have more than ... We were working on a Antlr parser for PHP, ... But it does not actually contain any builtin PHP methods. ...
    (alt.php)
  • Re: PHP compiler
    ... >built in functions. ... But, anyway, my compiler doesn't have to have more than ... We were working on a Antlr parser for PHP, ... But it does not actually contain any builtin PHP methods. ...
    (comp.lang.php)