RE: C struct
- Posted by Derek Parnell <Derek.Parnell at SYD.RABOBANK.COM> Jun 18, 2002
- 420 views
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C2174E.4B3FDE40 charset=iso-8859-1 > -----Original Message----- > From: tone.skoda at gmx.net [mailto:tone.skoda at gmx.net] > Subject: Re: C struct > > > > ----- Original Message ----- > From: "Derek Parnell" <Derek.Parnell at SYD.RABOBANK.COM> > > > node_parm = allot({MAXP, Ptr}), > > How do I store() to node_parm[3]? > The only way, it seems to me, is this way: > > tmp = node_parm > tmp [1] += 4*2 > store (p, tmp, val) > Tone, that method would work okay, but it is messy. There is a minor update to tk_mem.e that would make it much easier though. In the routine "allot()" replace the line... return { soFar, i, lCnt } with... return { soFar, i, lCnt, size } in the routine "store()" replace the lines ... where = s[1] + struct datatype = s[2] lCnt = s[3] with... datatype = s[2] lCnt = s[3] if length(s) > 4 and integer(s[5]) and s[5] > 0 and s[5] <= lCnt then s[5] = (s[5]-1) * s[4] else s &= 0 end if where = s[1] + struct + s[5] in the routine "fetch()" replace the lines ... at = struct + s[1] -- get data size size = s[2] -- get repeation cnt = s[3] with... -- get data size size = s[2] -- get repeation cnt = s[3] if length(s) > 4 and integer(s[5]) and s[5] > 0 and s[5] <= cnt then s[5] = (s[5]-1) * s[4] cnt = 1 -- Force fetch of single element. else s &= 0 end if -- address is struct + offset at = s[1] + struct + s[5] Once these changes are done, you can use store() and fetch() to easily handle the data. For example: -- Put 'val' into the 2nd element of node_parm store (p, node_parm & 2, val) -- Put 'val' into the 1st element of node_parm store (p, node_parm & 1, val) -- An alternate way to put 'val' into the 1st element of node_parm store (p, node_parm, val) -- Get the 3rd element of node_parm val = fetch(p, node_parm & 3) -- Get ALL the elements of node_parm sval = fetch(p, node_parm) Note that store() and fetch() do bounds checking so you can't put anything into other structure fields by accident. Hope this helps. (Note, I've made this change for the next release). -------------- Derek ================================================================== De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. ================================================================== The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail. ================================================================== ------_=_NextPart_000_01C2174E.4B3FDE40 Content-Type: application/ms-tnef