1. RE: C struct

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_01C2165E.FA4862E0
 charset=iso-8859-2

Here is my version Tone...

  node_name = allot( {8, Byte}),  -- char[8] means fixed size of 8 bytes
  node_parm = allot(Ptr),   -- struct node *parm[MAXP] means a pointer to an
array of MAXP node structures.
  node_tag = allot(Word),
  node_value = allot( {8, Byte}), --  double means double-precision floating
point value
 node_sx     = allot( Word ),
 node_sy     = allot( Word ),
 node_px     = allot( Word ),
 node_py     = allot( Word ),
 node_ay     = allot( Word ),
 node_kind   = allot( Word ),
 node_nump   = allot( Word ),
 node_msg    = allot( Lpsz ),
 node_next   = allot( Ptr ),
 sizeof_node = allotted_size()

> -----Original Message-----
> From: tone.skoda at gmx.net [mailto:tone.skoda at gmx.net]
> Sent: Tuesday, 18 June 2002 10:01
> To: EUforum
> Subject: C struct
> 
> 
> 
> Did I wrap this C structure right. I get Windows error when 
> trying to use
> function from
> dll.
> 
> MAXP = 5
> typedef struct node {
>   char name[8];
>   struct node *parm[MAXP];
>   short tag;
>   double value;
>   short sx,sy;       /* size */
>   short px,py;      /* location on scrn */
>   short ay;         /* adjust y */
>   short kind;
>   short nump;
>   char *msg;
>   struct node *next;
> } node;
> 
> node_name   = allot( {8, Strz} ),
> node_parm   = allot( {MAXP * 4, Strz} ),
> node_tag    = allot( Word ),
> node_value  = allot( DWord ),
> node_sx     = allot( Word ),
> node_sy     = allot( Word ),
> node_px     = allot( Word ),
> node_py     = allot( Word ),
> node_ay     = allot( Word ),
> node_kind   = allot( Word ),
> node_nump   = allot( Word ),
> node_msg    = allot( Lpsz ),
> node_next   = allot( Ptr ),
> sizeof_node = allotted_size(),
> 
> 
> 
> 

==================================================================
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_01C2165E.FA4862E0
Content-Type: application/ms-tnef

new topic     » topic index » view message » categorize

2. RE: C struct

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_01C21661.A709A0A0
 charset=iso-8859-2



> -----Original Message-----
> From: Derek Parnell 
> Subject: RE: C struct
> 
> 
> 
>   node_parm = allot(Ptr),   -- struct node *parm[MAXP] means 
> a pointer to an array of MAXP node structures.

Or am I wrong with this one? Maybe it should be ...

  node_parm = allot({MAXP, Ptr}), 

I'm unsure now if 
  struct node *parm[MAXP] 
means a single pointer to MAXP node structures

or  MAXP pointers to node structures.

Sorry. But I don't have a C manual handy at the moment.


-----------
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_01C21661.A709A0A0
Content-Type: application/ms-tnef

new topic     » goto parent     » topic index » view message » categorize

3. RE: C struct

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu