To be totally correct the flag is %p. That will print a pointer in whatever
notation is appropriate to the platform. Of course for z, that format is
08X. Unless it's 64-bit z.

Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf
Of Gibney, Dave
Sent: Friday, November 04, 2011 4:11 PM
To: [email protected]
Subject: Re: C newbie - pass a LDAP handle out to calling routine

First, thanks for the display in hex, that will help me a lot in future C
(if I'm ever here again after this project)

I've found the discussion of cast in the FM, it is several chapters down
from where I was in a straight thru read of the Language reference.  It
looks like this will let me make progress.

I said a language is a language and it's true, but I also know it takes a
lot of practice to become fluent. I may not see C again for years once I get
this thing working. I really appreciate the help the listserves can provide/

Dave Gibney
Information Technology Services
Washington State University


> -----Original Message-----
> From: IBM Mainframe Discussion List [mailto:[email protected]] On 
> Behalf Of Don Poitras
> Sent: Friday, November 04, 2011 3:55 PM
> To: [email protected]
> Subject: Re: C newbie - pass a LDAP handle out to calling routine
> 
> Dave,
>   You need to cast to a pointer type that memcpy (or whatever) can 
> handle. e.g.
> 
>  memcpy(foo, *((char *) ld), 10);
> 
> If you want to use this a lot, it might be better to just copy to a 
> pointer of another type:
> 
>  char *bar;
> 
>  bar = (char *) ld;
>  memcpy(foo, *bar, 10);
> 
> Also, I find it beneficial to display addresses in hex. e.g.
> 
> printf("ld before bind   :%08X\n",ld);
> 
> In article <0DE6A9840123E547B061AC5B6765C0261C148A@EXMB-
> 05.ad.wsu.edu> you wrote:
> >   This is my first experience with C, but a language is a language 
> > after the
> 3rd or 4th :)
> > I'm calling C for LDAP queries from Natural (Software AG "4"GL) in
batch.
> And it works, sort of.
> > One FM is IBM Tivoli Directory Server Client Programming for z/OS
> 
> >   If I use the sequence ldap_init, ldap_simple_bind_s, ldap_search,
> ldap_unbind, it gets overloaded after 5 calls at the speed of batch. 
> If I leave out the unbind, it works for thousands of calls, but there 
> is an obvious memory leak.
> >   So, I want to anchor the ldap handle in the main driving program. 
> > I made a
> simple C stub:
> >
> > extern int ret2nat (int  *back_value, LDAP *ld, char *msg) #include 
> > <ldap.h>
> 
> > In ldap.h there is:
> > typedef struct ldap LDAP;
> 
> > The examples use:
> > LDAP * ld;
> > To declare an ldap_handle which according to the listing is an:
> > ld                  6270-1:1931     Class = parameter, Length = 4
> >                                     Type = pointer to incomplete 
> > struct ldap
> >
> > I have a function:
> > LDAP * bind_adlds(char *hostname, char *container, char *msg) And I 
> > call it:
> > printf("ld before bind   :%d\n",ld);           /* ld before bind
:286352012
> > ld = bind_adlds(hostname, container, msg) ;
> > printf("ld after bind    :%d\n",ld);            /* ld after bind
:283317144
> 
> > but the value is not returned to the caller of ret2nat.
> >
> > Any attempts to use *ld in an assignment or even memcpy() get a 
> > complier
> message:
> > ERROR CCN3285 /u/ldap/test.c:46    The indirection operator cannot be
> applied to a pointer to an incomplete struct or union.
> > Or
> > WARNING CCN3068 /u/ldap/test.c:46    Operation between types "int*"
> and "pointer to an incomplete type" is not allowed.
> 
> > As I said, I am just learning how to spell C. I know I am fighting 
> > some kind of
> battle of types. I welcome even derisive comments, if in the end thay
help.
> 
> > Dave Gibney
> > Information Technology Services
> > Washington State University
> 
> --
> Don Poitras - SAS Development  -  SAS Institute Inc. - SAS Campus Drive
> [email protected]           (919) 531-5637                Cary, NC 27513
> 
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions, send 
> email to [email protected] with the message: GET IBM-MAIN INFO 
> Search the archives at http://bama.ua.edu/archives/ibm-main.html

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email
to [email protected] with the message: GET IBM-MAIN INFO Search the
archives at http://bama.ua.edu/archives/ibm-main.html

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to