Union's are pretty much the same as a data structure in RPG redefining
the same storage.


        int     int_val;
        char    str_val;
        } val;

would be in (sortof) RPG (non-ILE cause I don't RPGILE, would rather

mystruct DS
1 4  INT_VAL

Eg:  Memory positions 1 & 2 are shared by both INT_PTR and CHAR_PTR

Positions 3 & 4 are for INT_PTR only.

The usage in the example is pretty lame.

They should have declared a void pointer, and then cast it to int or
char.  But that's my Humble Opinion.

As to using pointers in RPG all I can say is YUCK.  I'll do it in C and
then give RPG the results.  But, if I didn't know C, then I'd probably
love them.


-----Original Message-----
From: c400-l-admin@midrange.com [mailto:c400-l-admin@midrange.com]On
Behalf Of Buck Calabro
Sent: Wednesday, November 28, 2001 3:40 PM
To: c400-l@midrange.com
Subject: RE: [C400-L] C to RPG prototyping

>struct _varBind{ struct _varBind * next;
>char *oid; /* Null Terminated */
>unsigned char asn_type;
>int val_len;
>union { int * int_val; char * str_val; } val; };

>0009.00 D pdu_ptr_s       S               *
>0010.00 D pdu_ds          DS                   based(pdu_ptr_s)
>0011.00 D  next                           *
>0012.00 D  oid                            *
>0013.00 D  asn_type                       *
>0014.00 D  val_len                      10I 0
>0015.00 D  result                         *
>So if I do this and snmpget returns OK, the 'result' field
>(from the DS) is
>*NULL but in debug an 'eval pdu_ds' shows 'result' is a valid
>So my 2 questions are:
>1) Is the api translated to rpg ok

I can't help because I don't understand union {}

>2) can i access %str(result) or should I be doing something else.

I would say you should be doing something else.  "result" is a pointer
something.  You need to create a space for that something, just as you
for pdu_ds.  The function returns a pointer and that pointer points to
pdu_ds memory space.  Since I don't know what union {} does, I can't
you what sort of space to create; perhaps another data structure?  Then
could address the data being pointed to by "result."
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/c400-l
or email: C400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.